Compare commits
49 Commits
Author | SHA1 | Date | |
---|---|---|---|
59ddb26628 | |||
83fda10f6e | |||
d97e995e59 | |||
56b2f84702 | |||
698e36bbd2 | |||
6ce49a2dc7 | |||
ccd330ba0f | |||
95d252b7b8 | |||
add681144b | |||
c6dc00815a | |||
99f04ac1a6 | |||
ce09450743 | |||
2cb80f37d4 | |||
827069e784 | |||
1a919e99b2 | |||
f77bebac80 | |||
6fbf279fac | |||
344f4f52c1 | |||
eb212aa91b | |||
a6dbb2ad2b | |||
595e514f18 | |||
07435ad844 | |||
1668ba913f | |||
a830eb666b | |||
cfc75d7e78 | |||
c525d7d9a9 | |||
1a0a351a15 | |||
bd3335c143 | |||
a94445b23e | |||
0c3421973c | |||
0afa8f2c14 | |||
d25a084858 | |||
311ca3c3f1 | |||
3193ef1083 | |||
5a878ae9af | |||
1828bc949e | |||
c0f2491eae | |||
d7c6474729 | |||
1ecc8fbc3b | |||
888402ecaf | |||
971d24aef0 | |||
c41fddd25e | |||
2ebe929fa5 | |||
53d096e392 | |||
4cc00bb4b1 | |||
c98b7fc702 | |||
e65effcb05 | |||
c1ed150949 | |||
c634eb4054 |
@ -11,7 +11,7 @@
|
|||||||
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.18" />
|
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.18" />
|
||||||
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.18" />
|
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.18" />
|
||||||
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
|
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
|
||||||
<PackageVersion Include="Concentus" Version="1.1.7" />
|
<PackageVersion Include="Concentus" Version="2.2.0" />
|
||||||
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
|
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
|
||||||
<PackageVersion Include="DynamicData" Version="8.4.1" />
|
<PackageVersion Include="DynamicData" Version="8.4.1" />
|
||||||
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
|
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
|
||||||
@ -20,9 +20,9 @@
|
|||||||
<PackageVersion Include="LibHac" Version="0.19.0" />
|
<PackageVersion Include="LibHac" Version="0.19.0" />
|
||||||
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
||||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
|
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
|
||||||
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
|
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.6.2" />
|
||||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||||
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
|
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
|
||||||
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
|
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
|
||||||
<PackageVersion Include="NetCoreServer" Version="8.0.7" />
|
<PackageVersion Include="NetCoreServer" Version="8.0.7" />
|
||||||
<PackageVersion Include="NUnit" Version="3.13.3" />
|
<PackageVersion Include="NUnit" Version="3.13.3" />
|
||||||
@ -49,4 +49,4 @@
|
|||||||
<PackageVersion Include="System.Management" Version="8.0.0" />
|
<PackageVersion Include="System.Management" Version="8.0.0" />
|
||||||
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -237,7 +237,7 @@ namespace ARMeilleure.CodeGen.Arm64
|
|||||||
long originalPosition = _stream.Position;
|
long originalPosition = _stream.Position;
|
||||||
|
|
||||||
_stream.Seek(0, SeekOrigin.Begin);
|
_stream.Seek(0, SeekOrigin.Begin);
|
||||||
_stream.Read(code, 0, code.Length);
|
_stream.ReadExactly(code, 0, code.Length);
|
||||||
_stream.Seek(originalPosition, SeekOrigin.Begin);
|
_stream.Seek(originalPosition, SeekOrigin.Begin);
|
||||||
|
|
||||||
RelocInfo relocInfo;
|
RelocInfo relocInfo;
|
||||||
|
@ -251,7 +251,20 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectedReg = GetHighestValueIndex(freePositions);
|
// If this is a copy destination variable, we prefer the register used for the copy source.
|
||||||
|
// If the register is available, then the copy can be eliminated later as both source
|
||||||
|
// and destination will use the same register.
|
||||||
|
int selectedReg;
|
||||||
|
|
||||||
|
if (current.TryGetCopySourceRegister(out int preferredReg) && freePositions[preferredReg] >= current.GetEnd())
|
||||||
|
{
|
||||||
|
selectedReg = preferredReg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectedReg = GetHighestValueIndex(freePositions);
|
||||||
|
}
|
||||||
|
|
||||||
int selectedNextUse = freePositions[selectedReg];
|
int selectedNextUse = freePositions[selectedReg];
|
||||||
|
|
||||||
// Intervals starts and ends at odd positions, unless they span an entire
|
// Intervals starts and ends at odd positions, unless they span an entire
|
||||||
@ -431,7 +444,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetHighestValueIndex(Span<int> span)
|
private static int GetHighestValueIndex(ReadOnlySpan<int> span)
|
||||||
{
|
{
|
||||||
int highest = int.MinValue;
|
int highest = int.MinValue;
|
||||||
|
|
||||||
@ -798,12 +811,12 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
// The "visited" state is stored in the MSB of the local's value.
|
// The "visited" state is stored in the MSB of the local's value.
|
||||||
const ulong VisitedMask = 1ul << 63;
|
const ulong VisitedMask = 1ul << 63;
|
||||||
|
|
||||||
bool IsVisited(Operand local)
|
static bool IsVisited(Operand local)
|
||||||
{
|
{
|
||||||
return (local.GetValueUnsafe() & VisitedMask) != 0;
|
return (local.GetValueUnsafe() & VisitedMask) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVisited(Operand local)
|
static void SetVisited(Operand local)
|
||||||
{
|
{
|
||||||
local.GetValueUnsafe() |= VisitedMask;
|
local.GetValueUnsafe() |= VisitedMask;
|
||||||
}
|
}
|
||||||
@ -826,9 +839,25 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
{
|
{
|
||||||
dest.NumberLocal(_intervals.Count);
|
dest.NumberLocal(_intervals.Count);
|
||||||
|
|
||||||
_intervals.Add(new LiveInterval(dest));
|
LiveInterval interval = new LiveInterval(dest);
|
||||||
|
_intervals.Add(interval);
|
||||||
|
|
||||||
SetVisited(dest);
|
SetVisited(dest);
|
||||||
|
|
||||||
|
// If this is a copy (or copy-like operation), set the copy source interval as well.
|
||||||
|
// This is used for register preferencing later on, which allows the copy to be eliminated
|
||||||
|
// in some cases.
|
||||||
|
if (node.Instruction == Instruction.Copy || node.Instruction == Instruction.ZeroExtend32)
|
||||||
|
{
|
||||||
|
Operand source = node.GetSource(0);
|
||||||
|
|
||||||
|
if (source.Kind == OperandKind.LocalVariable &&
|
||||||
|
source.GetLocalNumber() > 0 &&
|
||||||
|
(node.Instruction == Instruction.Copy || source.Type == OperandType.I32))
|
||||||
|
{
|
||||||
|
interval.SetCopySource(_intervals[source.GetLocalNumber()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
public LiveRange CurrRange;
|
public LiveRange CurrRange;
|
||||||
|
|
||||||
public LiveInterval Parent;
|
public LiveInterval Parent;
|
||||||
|
public LiveInterval CopySource;
|
||||||
|
|
||||||
public UseList Uses;
|
public UseList Uses;
|
||||||
public LiveIntervalList Children;
|
public LiveIntervalList Children;
|
||||||
@ -37,6 +38,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
private ref LiveRange CurrRange => ref _data->CurrRange;
|
private ref LiveRange CurrRange => ref _data->CurrRange;
|
||||||
private ref LiveRange PrevRange => ref _data->PrevRange;
|
private ref LiveRange PrevRange => ref _data->PrevRange;
|
||||||
private ref LiveInterval Parent => ref _data->Parent;
|
private ref LiveInterval Parent => ref _data->Parent;
|
||||||
|
private ref LiveInterval CopySource => ref _data->CopySource;
|
||||||
private ref UseList Uses => ref _data->Uses;
|
private ref UseList Uses => ref _data->Uses;
|
||||||
private ref LiveIntervalList Children => ref _data->Children;
|
private ref LiveIntervalList Children => ref _data->Children;
|
||||||
|
|
||||||
@ -78,6 +80,25 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
|
|||||||
Register = register;
|
Register = register;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetCopySource(LiveInterval copySource)
|
||||||
|
{
|
||||||
|
CopySource = copySource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetCopySourceRegister(out int copySourceRegIndex)
|
||||||
|
{
|
||||||
|
if (CopySource._data != null)
|
||||||
|
{
|
||||||
|
copySourceRegIndex = CopySource.Register.Index;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
copySourceRegIndex = 0;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
PrevRange = default;
|
PrevRange = default;
|
||||||
|
@ -1444,7 +1444,7 @@ namespace ARMeilleure.CodeGen.X86
|
|||||||
|
|
||||||
Span<byte> buffer = new byte[jump.JumpPosition - _stream.Position];
|
Span<byte> buffer = new byte[jump.JumpPosition - _stream.Position];
|
||||||
|
|
||||||
_stream.Read(buffer);
|
_stream.ReadExactly(buffer);
|
||||||
_stream.Seek(ReservedBytesForJump, SeekOrigin.Current);
|
_stream.Seek(ReservedBytesForJump, SeekOrigin.Current);
|
||||||
|
|
||||||
codeStream.Write(buffer);
|
codeStream.Write(buffer);
|
||||||
|
@ -11,7 +11,7 @@ namespace ARMeilleure.Translation
|
|||||||
private int[] _postOrderMap;
|
private int[] _postOrderMap;
|
||||||
|
|
||||||
public int LocalsCount { get; private set; }
|
public int LocalsCount { get; private set; }
|
||||||
public BasicBlock Entry { get; }
|
public BasicBlock Entry { get; private set; }
|
||||||
public IntrusiveList<BasicBlock> Blocks { get; }
|
public IntrusiveList<BasicBlock> Blocks { get; }
|
||||||
public BasicBlock[] PostOrderBlocks => _postOrderBlocks;
|
public BasicBlock[] PostOrderBlocks => _postOrderBlocks;
|
||||||
public int[] PostOrderMap => _postOrderMap;
|
public int[] PostOrderMap => _postOrderMap;
|
||||||
@ -34,6 +34,15 @@ namespace ARMeilleure.Translation
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateEntry(BasicBlock newEntry)
|
||||||
|
{
|
||||||
|
newEntry.AddSuccessor(Entry);
|
||||||
|
|
||||||
|
Entry = newEntry;
|
||||||
|
Blocks.AddFirst(newEntry);
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
RemoveUnreachableBlocks(Blocks);
|
RemoveUnreachableBlocks(Blocks);
|
||||||
|
@ -29,7 +29,7 @@ namespace ARMeilleure.Translation.PTC
|
|||||||
private const string OuterHeaderMagicString = "PTCohd\0\0";
|
private const string OuterHeaderMagicString = "PTCohd\0\0";
|
||||||
private const string InnerHeaderMagicString = "PTCihd\0\0";
|
private const string InnerHeaderMagicString = "PTCihd\0\0";
|
||||||
|
|
||||||
private const uint InternalVersion = 6634; //! To be incremented manually for each change to the ARMeilleure project.
|
private const uint InternalVersion = 6950; //! To be incremented manually for each change to the ARMeilleure project.
|
||||||
|
|
||||||
private const string ActualDir = "0";
|
private const string ActualDir = "0";
|
||||||
private const string BackupDir = "1";
|
private const string BackupDir = "1";
|
||||||
|
@ -89,6 +89,17 @@ namespace ARMeilleure.Translation
|
|||||||
|
|
||||||
public static void RunPass(ControlFlowGraph cfg, ExecutionMode mode)
|
public static void RunPass(ControlFlowGraph cfg, ExecutionMode mode)
|
||||||
{
|
{
|
||||||
|
if (cfg.Entry.Predecessors.Count != 0)
|
||||||
|
{
|
||||||
|
// We expect the entry block to have no predecessors.
|
||||||
|
// This is required because we have a implicit context load at the start of the function,
|
||||||
|
// but if there is a jump to the start of the function, the context load would trash the modified values.
|
||||||
|
// Here we insert a new entry block that will jump to the existing entry block.
|
||||||
|
BasicBlock newEntry = new BasicBlock(cfg.Blocks.Count);
|
||||||
|
|
||||||
|
cfg.UpdateEntry(newEntry);
|
||||||
|
}
|
||||||
|
|
||||||
// Compute local register inputs and outputs used inside blocks.
|
// Compute local register inputs and outputs used inside blocks.
|
||||||
RegisterMask[] localInputs = new RegisterMask[cfg.Blocks.Count];
|
RegisterMask[] localInputs = new RegisterMask[cfg.Blocks.Count];
|
||||||
RegisterMask[] localOutputs = new RegisterMask[cfg.Blocks.Count];
|
RegisterMask[] localOutputs = new RegisterMask[cfg.Blocks.Count];
|
||||||
@ -201,7 +212,7 @@ namespace ARMeilleure.Translation
|
|||||||
|
|
||||||
// The only block without any predecessor should be the entry block.
|
// The only block without any predecessor should be the entry block.
|
||||||
// It always needs a context load as it is the first block to run.
|
// It always needs a context load as it is the first block to run.
|
||||||
if (block.Predecessors.Count == 0 || hasContextLoad)
|
if (block == cfg.Entry || hasContextLoad)
|
||||||
{
|
{
|
||||||
long vecMask = globalInputs[block.Index].VecMask;
|
long vecMask = globalInputs[block.Index].VecMask;
|
||||||
long intMask = globalInputs[block.Index].IntMask;
|
long intMask = globalInputs[block.Index].IntMask;
|
||||||
|
@ -89,9 +89,9 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using IMemoryOwner<byte> samplesOwner = ByteMemoryPool.Rent(frameCount * _bytesPerFrame);
|
using SpanOwner<byte> samplesOwner = SpanOwner<byte>.Rent(frameCount * _bytesPerFrame);
|
||||||
|
|
||||||
Span<byte> samples = samplesOwner.Memory.Span;
|
Span<byte> samples = samplesOwner.Span;
|
||||||
|
|
||||||
_ringBuffer.Read(samples, 0, samples.Length);
|
_ringBuffer.Read(samples, 0, samples.Length);
|
||||||
|
|
||||||
|
@ -122,9 +122,9 @@ namespace Ryujinx.Audio.Backends.SoundIo
|
|||||||
|
|
||||||
int channelCount = areas.Length;
|
int channelCount = areas.Length;
|
||||||
|
|
||||||
using IMemoryOwner<byte> samplesOwner = ByteMemoryPool.Rent(frameCount * bytesPerFrame);
|
using SpanOwner<byte> samplesOwner = SpanOwner<byte>.Rent(frameCount * bytesPerFrame);
|
||||||
|
|
||||||
Span<byte> samples = samplesOwner.Memory.Span;
|
Span<byte> samples = samplesOwner.Span;
|
||||||
|
|
||||||
_ringBuffer.Read(samples, 0, samples.Length);
|
_ringBuffer.Read(samples, 0, samples.Length);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace Ryujinx.Audio.Backends.Common
|
|||||||
|
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new();
|
||||||
|
|
||||||
private IMemoryOwner<byte> _bufferOwner;
|
private MemoryOwner<byte> _bufferOwner;
|
||||||
private Memory<byte> _buffer;
|
private Memory<byte> _buffer;
|
||||||
private int _size;
|
private int _size;
|
||||||
private int _headOffset;
|
private int _headOffset;
|
||||||
@ -24,7 +24,7 @@ namespace Ryujinx.Audio.Backends.Common
|
|||||||
|
|
||||||
public DynamicRingBuffer(int initialCapacity = RingBufferAlignment)
|
public DynamicRingBuffer(int initialCapacity = RingBufferAlignment)
|
||||||
{
|
{
|
||||||
_bufferOwner = ByteMemoryPool.RentCleared(initialCapacity);
|
_bufferOwner = MemoryOwner<byte>.RentCleared(initialCapacity);
|
||||||
_buffer = _bufferOwner.Memory;
|
_buffer = _bufferOwner.Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ namespace Ryujinx.Audio.Backends.Common
|
|||||||
|
|
||||||
private void SetCapacityLocked(int capacity)
|
private void SetCapacityLocked(int capacity)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> newBufferOwner = ByteMemoryPool.RentCleared(capacity);
|
MemoryOwner<byte> newBufferOwner = MemoryOwner<byte>.RentCleared(capacity);
|
||||||
Memory<byte> newBuffer = newBufferOwner.Memory;
|
Memory<byte> newBuffer = newBufferOwner.Memory;
|
||||||
|
|
||||||
if (_size > 0)
|
if (_size > 0)
|
||||||
|
@ -18,16 +18,12 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
|||||||
|
|
||||||
if (version == 2)
|
if (version == 2)
|
||||||
{
|
{
|
||||||
return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion2,
|
return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion2, PerformanceEntryVersion2, PerformanceDetailVersion2>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
|
||||||
PerformanceEntryVersion2,
|
|
||||||
PerformanceDetailVersion2>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version == 1)
|
if (version == 1)
|
||||||
{
|
{
|
||||||
return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion1,
|
return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion1, PerformanceEntryVersion1, PerformanceDetailVersion1>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
|
||||||
PerformanceEntryVersion1,
|
|
||||||
PerformanceDetailVersion1>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException($"Unknown Performance metrics data format version {version}");
|
throw new NotImplementedException($"Unknown Performance metrics data format version {version}");
|
||||||
|
@ -234,7 +234,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
|||||||
{
|
{
|
||||||
performanceEntry = null;
|
performanceEntry = null;
|
||||||
|
|
||||||
if (_entryDetailIndex > MaxFrameDetailCount)
|
if (_entryDetailIndex >= MaxFrameDetailCount)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
|||||||
EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(),
|
EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(),
|
||||||
};
|
};
|
||||||
|
|
||||||
uint baseEntryOffset = (uint)(Unsafe.SizeOf<THeader>() + GetEntriesSize() + Unsafe.SizeOf<IPerformanceDetailEntry>() * _entryDetailIndex);
|
uint baseEntryOffset = (uint)(Unsafe.SizeOf<THeader>() + GetEntriesSize() + Unsafe.SizeOf<TEntryDetail>() * _entryDetailIndex);
|
||||||
|
|
||||||
ref TEntryDetail entryDetail = ref EntriesDetail[_entryDetailIndex];
|
ref TEntryDetail entryDetail = ref EntriesDetail[_entryDetailIndex];
|
||||||
|
|
||||||
|
140
src/Ryujinx.Common/Memory/MemoryOwner.cs
Normal file
140
src/Ryujinx.Common/Memory/MemoryOwner.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
#nullable enable
|
||||||
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Ryujinx.Common.Memory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An <see cref="IMemoryOwner{T}"/> implementation with an embedded length and fast <see cref="Span{T}"/>
|
||||||
|
/// accessor, with memory allocated from <seealso cref="ArrayPool{T}.Shared"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of item to store.</typeparam>
|
||||||
|
public sealed class MemoryOwner<T> : IMemoryOwner<T>
|
||||||
|
{
|
||||||
|
private readonly int _length;
|
||||||
|
private T[]? _array;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="MemoryOwner{T}"/> class with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
private MemoryOwner(int length)
|
||||||
|
{
|
||||||
|
_length = length;
|
||||||
|
_array = ArrayPool<T>.Shared.Rent(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the specified length.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
/// <returns>A <see cref="MemoryOwner{T}"/> instance of the requested length</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="length"/> is not valid</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static MemoryOwner<T> Rent(int length) => new(length);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the specified length and the content cleared.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
/// <returns>A <see cref="MemoryOwner{T}"/> instance of the requested length and the content cleared</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="length"/> is not valid</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static MemoryOwner<T> RentCleared(int length)
|
||||||
|
{
|
||||||
|
MemoryOwner<T> result = new(length);
|
||||||
|
|
||||||
|
result._array.AsSpan(0, length).Clear();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the content copied from the specified buffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">The buffer to copy</param>
|
||||||
|
/// <returns>A <see cref="MemoryOwner{T}"/> instance with the same length and content as <paramref name="buffer"/></returns>
|
||||||
|
public static MemoryOwner<T> RentCopy(ReadOnlySpan<T> buffer)
|
||||||
|
{
|
||||||
|
MemoryOwner<T> result = new(buffer.Length);
|
||||||
|
|
||||||
|
buffer.CopyTo(result._array);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of items in the current instance.
|
||||||
|
/// </summary>
|
||||||
|
public int Length
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public Memory<T> Memory
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get
|
||||||
|
{
|
||||||
|
T[]? array = _array;
|
||||||
|
|
||||||
|
if (array is null)
|
||||||
|
{
|
||||||
|
ThrowObjectDisposedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new(array, 0, _length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="Span{T}"/> wrapping the memory belonging to the current instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Uses a trick made possible by the .NET 6+ runtime array layout.
|
||||||
|
/// </remarks>
|
||||||
|
public Span<T> Span
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get
|
||||||
|
{
|
||||||
|
T[]? array = _array;
|
||||||
|
|
||||||
|
if (array is null)
|
||||||
|
{
|
||||||
|
ThrowObjectDisposedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
ref T firstElementRef = ref MemoryMarshal.GetArrayDataReference(array);
|
||||||
|
|
||||||
|
return MemoryMarshal.CreateSpan(ref firstElementRef, _length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
T[]? array = Interlocked.Exchange(ref _array, null);
|
||||||
|
|
||||||
|
if (array is not null)
|
||||||
|
{
|
||||||
|
ArrayPool<T>.Shared.Return(array, RuntimeHelpers.IsReferenceOrContainsReferences<T>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Throws an <see cref="ObjectDisposedException"/> when <see cref="_array"/> is <see langword="null"/>.
|
||||||
|
/// </summary>
|
||||||
|
[DoesNotReturn]
|
||||||
|
private static void ThrowObjectDisposedException()
|
||||||
|
{
|
||||||
|
throw new ObjectDisposedException(nameof(MemoryOwner<T>), "The buffer has already been disposed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
114
src/Ryujinx.Common/Memory/SpanOwner.cs
Normal file
114
src/Ryujinx.Common/Memory/SpanOwner.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Ryujinx.Common.Memory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A stack-only type that rents a buffer of a specified length from <seealso cref="ArrayPool{T}.Shared"/>.
|
||||||
|
/// It does not implement <see cref="IDisposable"/> to avoid being boxed, but should still be disposed. This
|
||||||
|
/// is easy since C# 8, which allows use of C# `using` constructs on any type that has a public Dispose() method.
|
||||||
|
/// To keep this type simple, fast, and read-only, it does not check or guard against multiple disposals.
|
||||||
|
/// For all these reasons, all usage should be with a `using` block or statement.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of item to store.</typeparam>
|
||||||
|
public readonly ref struct SpanOwner<T>
|
||||||
|
{
|
||||||
|
private readonly int _length;
|
||||||
|
private readonly T[] _array;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SpanOwner{T}"/> struct with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
private SpanOwner(int length)
|
||||||
|
{
|
||||||
|
_length = length;
|
||||||
|
_array = ArrayPool<T>.Shared.Rent(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an empty <see cref="SpanOwner{T}"/> instance.
|
||||||
|
/// </summary>
|
||||||
|
public static SpanOwner<T> Empty
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => new(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="SpanOwner{T}"/> instance with the specified length.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
/// <returns>A <see cref="SpanOwner{T}"/> instance of the requested length</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="length"/> is not valid</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static SpanOwner<T> Rent(int length) => new(length);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="SpanOwner{T}"/> instance with the length and the content cleared.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="length">The length of the new memory buffer to use</param>
|
||||||
|
/// <returns>A <see cref="SpanOwner{T}"/> instance of the requested length and the content cleared</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="length"/> is not valid</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static SpanOwner<T> RentCleared(int length)
|
||||||
|
{
|
||||||
|
SpanOwner<T> result = new(length);
|
||||||
|
|
||||||
|
result._array.AsSpan(0, length).Clear();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="SpanOwner{T}"/> instance with the content copied from the specified buffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">The buffer to copy</param>
|
||||||
|
/// <returns>A <see cref="SpanOwner{T}"/> instance with the same length and content as <paramref name="buffer"/></returns>
|
||||||
|
public static SpanOwner<T> RentCopy(ReadOnlySpan<T> buffer)
|
||||||
|
{
|
||||||
|
SpanOwner<T> result = new(buffer.Length);
|
||||||
|
|
||||||
|
buffer.CopyTo(result._array);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of items in the current instance
|
||||||
|
/// </summary>
|
||||||
|
public int Length
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="Span{T}"/> wrapping the memory belonging to the current instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Uses a trick made possible by the .NET 6+ runtime array layout.
|
||||||
|
/// </remarks>
|
||||||
|
public Span<T> Span
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get
|
||||||
|
{
|
||||||
|
ref T firstElementRef = ref MemoryMarshal.GetArrayDataReference(_array);
|
||||||
|
|
||||||
|
return MemoryMarshal.CreateSpan(ref firstElementRef, _length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implements the duck-typed <see cref="IDisposable.Dispose"/> method.
|
||||||
|
/// </summary>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ArrayPool<T>.Shared.Return(_array, RuntimeHelpers.IsReferenceOrContainsReferences<T>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
@ -145,9 +144,9 @@ namespace Ryujinx.Graphics.Device
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> memoryOwner = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> memoryOwner = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
GetSpan(va, size).CopyTo(memoryOwner.Memory.Span);
|
ReadImpl(va, memoryOwner.Span);
|
||||||
|
|
||||||
return new WritableRegion(this, va, memoryOwner, tracked: true);
|
return new WritableRegion(this, va, memoryOwner, tracked: true);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,13 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
public readonly bool SupportsIndirectParameters;
|
public readonly bool SupportsIndirectParameters;
|
||||||
public readonly bool SupportsDepthClipControl;
|
public readonly bool SupportsDepthClipControl;
|
||||||
|
|
||||||
|
public readonly int UniformBufferSetIndex;
|
||||||
|
public readonly int StorageBufferSetIndex;
|
||||||
|
public readonly int TextureSetIndex;
|
||||||
|
public readonly int ImageSetIndex;
|
||||||
|
public readonly int ExtraSetBaseIndex;
|
||||||
|
public readonly int MaximumExtraSets;
|
||||||
|
|
||||||
public readonly uint MaximumUniformBuffersPerStage;
|
public readonly uint MaximumUniformBuffersPerStage;
|
||||||
public readonly uint MaximumStorageBuffersPerStage;
|
public readonly uint MaximumStorageBuffersPerStage;
|
||||||
public readonly uint MaximumTexturesPerStage;
|
public readonly uint MaximumTexturesPerStage;
|
||||||
@ -109,6 +116,12 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
bool supportsViewportSwizzle,
|
bool supportsViewportSwizzle,
|
||||||
bool supportsIndirectParameters,
|
bool supportsIndirectParameters,
|
||||||
bool supportsDepthClipControl,
|
bool supportsDepthClipControl,
|
||||||
|
int uniformBufferSetIndex,
|
||||||
|
int storageBufferSetIndex,
|
||||||
|
int textureSetIndex,
|
||||||
|
int imageSetIndex,
|
||||||
|
int extraSetBaseIndex,
|
||||||
|
int maximumExtraSets,
|
||||||
uint maximumUniformBuffersPerStage,
|
uint maximumUniformBuffersPerStage,
|
||||||
uint maximumStorageBuffersPerStage,
|
uint maximumStorageBuffersPerStage,
|
||||||
uint maximumTexturesPerStage,
|
uint maximumTexturesPerStage,
|
||||||
@ -164,6 +177,12 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
SupportsViewportSwizzle = supportsViewportSwizzle;
|
SupportsViewportSwizzle = supportsViewportSwizzle;
|
||||||
SupportsIndirectParameters = supportsIndirectParameters;
|
SupportsIndirectParameters = supportsIndirectParameters;
|
||||||
SupportsDepthClipControl = supportsDepthClipControl;
|
SupportsDepthClipControl = supportsDepthClipControl;
|
||||||
|
UniformBufferSetIndex = uniformBufferSetIndex;
|
||||||
|
StorageBufferSetIndex = storageBufferSetIndex;
|
||||||
|
TextureSetIndex = textureSetIndex;
|
||||||
|
ImageSetIndex = imageSetIndex;
|
||||||
|
ExtraSetBaseIndex = extraSetBaseIndex;
|
||||||
|
MaximumExtraSets = maximumExtraSets;
|
||||||
MaximumUniformBuffersPerStage = maximumUniformBuffersPerStage;
|
MaximumUniformBuffersPerStage = maximumUniformBuffersPerStage;
|
||||||
MaximumStorageBuffersPerStage = maximumStorageBuffersPerStage;
|
MaximumStorageBuffersPerStage = maximumStorageBuffersPerStage;
|
||||||
MaximumTexturesPerStage = maximumTexturesPerStage;
|
MaximumTexturesPerStage = maximumTexturesPerStage;
|
||||||
|
@ -711,5 +711,36 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
{
|
{
|
||||||
return format.IsUint() || format.IsSint();
|
return format.IsUint() || format.IsSint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the texture format is a float or sRGB color format.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Does not include normalized, compressed or depth formats.
|
||||||
|
/// Float and sRGB formats do not participate in logical operations.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="format">Texture format</param>
|
||||||
|
/// <returns>True if the format is a float or sRGB color format, false otherwise</returns>
|
||||||
|
public static bool IsFloatOrSrgb(this Format format)
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case Format.R8G8B8A8Srgb:
|
||||||
|
case Format.B8G8R8A8Srgb:
|
||||||
|
case Format.R16Float:
|
||||||
|
case Format.R16G16Float:
|
||||||
|
case Format.R16G16B16Float:
|
||||||
|
case Format.R16G16B16A16Float:
|
||||||
|
case Format.R32Float:
|
||||||
|
case Format.R32G32Float:
|
||||||
|
case Format.R32G32B32Float:
|
||||||
|
case Format.R32G32B32A32Float:
|
||||||
|
case Format.R11G11B10Float:
|
||||||
|
case Format.R9G9B9E5Float:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.GAL
|
namespace Ryujinx.Graphics.GAL
|
||||||
{
|
{
|
||||||
public interface IImageArray
|
public interface IImageArray : IDisposable
|
||||||
{
|
{
|
||||||
void SetFormats(int index, Format[] imageFormats);
|
void SetFormats(int index, Format[] imageFormats);
|
||||||
void SetImages(int index, ITexture[] images);
|
void SetImages(int index, ITexture[] images);
|
||||||
|
@ -60,6 +60,7 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
|
|
||||||
void SetImage(ShaderStage stage, int binding, ITexture texture, Format imageFormat);
|
void SetImage(ShaderStage stage, int binding, ITexture texture, Format imageFormat);
|
||||||
void SetImageArray(ShaderStage stage, int binding, IImageArray array);
|
void SetImageArray(ShaderStage stage, int binding, IImageArray array);
|
||||||
|
void SetImageArraySeparate(ShaderStage stage, int setIndex, IImageArray array);
|
||||||
|
|
||||||
void SetLineParameters(float width, bool smooth);
|
void SetLineParameters(float width, bool smooth);
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
|
|
||||||
void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler);
|
void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler);
|
||||||
void SetTextureArray(ShaderStage stage, int binding, ITextureArray array);
|
void SetTextureArray(ShaderStage stage, int binding, ITextureArray array);
|
||||||
|
void SetTextureArraySeparate(ShaderStage stage, int setIndex, ITextureArray array);
|
||||||
|
|
||||||
void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers);
|
void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers);
|
||||||
void SetUniformBuffers(ReadOnlySpan<BufferAssignment> buffers);
|
void SetUniformBuffers(ReadOnlySpan<BufferAssignment> buffers);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.GAL
|
namespace Ryujinx.Graphics.GAL
|
||||||
{
|
{
|
||||||
public interface ITextureArray
|
public interface ITextureArray : IDisposable
|
||||||
{
|
{
|
||||||
void SetSamplers(int index, ISampler[] samplers);
|
void SetSamplers(int index, ISampler[] samplers);
|
||||||
void SetTextures(int index, ITexture[] textures);
|
void SetTextures(int index, ITexture[] textures);
|
||||||
|
@ -66,6 +66,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
Register<CounterEventDisposeCommand>(CommandType.CounterEventDispose);
|
Register<CounterEventDisposeCommand>(CommandType.CounterEventDispose);
|
||||||
Register<CounterEventFlushCommand>(CommandType.CounterEventFlush);
|
Register<CounterEventFlushCommand>(CommandType.CounterEventFlush);
|
||||||
|
|
||||||
|
Register<ImageArrayDisposeCommand>(CommandType.ImageArrayDispose);
|
||||||
Register<ImageArraySetFormatsCommand>(CommandType.ImageArraySetFormats);
|
Register<ImageArraySetFormatsCommand>(CommandType.ImageArraySetFormats);
|
||||||
Register<ImageArraySetImagesCommand>(CommandType.ImageArraySetImages);
|
Register<ImageArraySetImagesCommand>(CommandType.ImageArraySetImages);
|
||||||
|
|
||||||
@ -88,6 +89,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
Register<TextureSetDataSliceRegionCommand>(CommandType.TextureSetDataSliceRegion);
|
Register<TextureSetDataSliceRegionCommand>(CommandType.TextureSetDataSliceRegion);
|
||||||
Register<TextureSetStorageCommand>(CommandType.TextureSetStorage);
|
Register<TextureSetStorageCommand>(CommandType.TextureSetStorage);
|
||||||
|
|
||||||
|
Register<TextureArrayDisposeCommand>(CommandType.TextureArrayDispose);
|
||||||
Register<TextureArraySetSamplersCommand>(CommandType.TextureArraySetSamplers);
|
Register<TextureArraySetSamplersCommand>(CommandType.TextureArraySetSamplers);
|
||||||
Register<TextureArraySetTexturesCommand>(CommandType.TextureArraySetTextures);
|
Register<TextureArraySetTexturesCommand>(CommandType.TextureArraySetTextures);
|
||||||
|
|
||||||
@ -124,6 +126,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
Register<SetUniformBuffersCommand>(CommandType.SetUniformBuffers);
|
Register<SetUniformBuffersCommand>(CommandType.SetUniformBuffers);
|
||||||
Register<SetImageCommand>(CommandType.SetImage);
|
Register<SetImageCommand>(CommandType.SetImage);
|
||||||
Register<SetImageArrayCommand>(CommandType.SetImageArray);
|
Register<SetImageArrayCommand>(CommandType.SetImageArray);
|
||||||
|
Register<SetImageArraySeparateCommand>(CommandType.SetImageArraySeparate);
|
||||||
Register<SetIndexBufferCommand>(CommandType.SetIndexBuffer);
|
Register<SetIndexBufferCommand>(CommandType.SetIndexBuffer);
|
||||||
Register<SetLineParametersCommand>(CommandType.SetLineParameters);
|
Register<SetLineParametersCommand>(CommandType.SetLineParameters);
|
||||||
Register<SetLogicOpStateCommand>(CommandType.SetLogicOpState);
|
Register<SetLogicOpStateCommand>(CommandType.SetLogicOpState);
|
||||||
@ -141,6 +144,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
Register<SetStencilTestCommand>(CommandType.SetStencilTest);
|
Register<SetStencilTestCommand>(CommandType.SetStencilTest);
|
||||||
Register<SetTextureAndSamplerCommand>(CommandType.SetTextureAndSampler);
|
Register<SetTextureAndSamplerCommand>(CommandType.SetTextureAndSampler);
|
||||||
Register<SetTextureArrayCommand>(CommandType.SetTextureArray);
|
Register<SetTextureArrayCommand>(CommandType.SetTextureArray);
|
||||||
|
Register<SetTextureArraySeparateCommand>(CommandType.SetTextureArraySeparate);
|
||||||
Register<SetUserClipDistanceCommand>(CommandType.SetUserClipDistance);
|
Register<SetUserClipDistanceCommand>(CommandType.SetUserClipDistance);
|
||||||
Register<SetVertexAttribsCommand>(CommandType.SetVertexAttribs);
|
Register<SetVertexAttribsCommand>(CommandType.SetVertexAttribs);
|
||||||
Register<SetVertexBuffersCommand>(CommandType.SetVertexBuffers);
|
Register<SetVertexBuffersCommand>(CommandType.SetVertexBuffers);
|
||||||
|
@ -26,6 +26,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
CounterEventDispose,
|
CounterEventDispose,
|
||||||
CounterEventFlush,
|
CounterEventFlush,
|
||||||
|
|
||||||
|
ImageArrayDispose,
|
||||||
ImageArraySetFormats,
|
ImageArraySetFormats,
|
||||||
ImageArraySetImages,
|
ImageArraySetImages,
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
TextureSetDataSliceRegion,
|
TextureSetDataSliceRegion,
|
||||||
TextureSetStorage,
|
TextureSetStorage,
|
||||||
|
|
||||||
|
TextureArrayDispose,
|
||||||
TextureArraySetSamplers,
|
TextureArraySetSamplers,
|
||||||
TextureArraySetTextures,
|
TextureArraySetTextures,
|
||||||
|
|
||||||
@ -84,6 +86,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
SetUniformBuffers,
|
SetUniformBuffers,
|
||||||
SetImage,
|
SetImage,
|
||||||
SetImageArray,
|
SetImageArray,
|
||||||
|
SetImageArraySeparate,
|
||||||
SetIndexBuffer,
|
SetIndexBuffer,
|
||||||
SetLineParameters,
|
SetLineParameters,
|
||||||
SetLogicOpState,
|
SetLogicOpState,
|
||||||
@ -101,6 +104,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
SetStencilTest,
|
SetStencilTest,
|
||||||
SetTextureAndSampler,
|
SetTextureAndSampler,
|
||||||
SetTextureArray,
|
SetTextureArray,
|
||||||
|
SetTextureArraySeparate,
|
||||||
SetUserClipDistance,
|
SetUserClipDistance,
|
||||||
SetVertexAttribs,
|
SetVertexAttribs,
|
||||||
SetVertexBuffers,
|
SetVertexBuffers,
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Resources;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.GAL.Multithreading.Commands.ImageArray
|
||||||
|
{
|
||||||
|
struct ImageArrayDisposeCommand : IGALCommand, IGALCommand<ImageArrayDisposeCommand>
|
||||||
|
{
|
||||||
|
public readonly CommandType CommandType => CommandType.ImageArrayDispose;
|
||||||
|
private TableRef<ThreadedImageArray> _imageArray;
|
||||||
|
|
||||||
|
public void Set(TableRef<ThreadedImageArray> imageArray)
|
||||||
|
{
|
||||||
|
_imageArray = imageArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run(ref ImageArrayDisposeCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||||
|
{
|
||||||
|
command._imageArray.Get(threaded).Base.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Resources;
|
||||||
|
using Ryujinx.Graphics.Shader;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
||||||
|
{
|
||||||
|
struct SetImageArraySeparateCommand : IGALCommand, IGALCommand<SetImageArraySeparateCommand>
|
||||||
|
{
|
||||||
|
public readonly CommandType CommandType => CommandType.SetImageArraySeparate;
|
||||||
|
private ShaderStage _stage;
|
||||||
|
private int _setIndex;
|
||||||
|
private TableRef<IImageArray> _array;
|
||||||
|
|
||||||
|
public void Set(ShaderStage stage, int setIndex, TableRef<IImageArray> array)
|
||||||
|
{
|
||||||
|
_stage = stage;
|
||||||
|
_setIndex = setIndex;
|
||||||
|
_array = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run(ref SetImageArraySeparateCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||||
|
{
|
||||||
|
renderer.Pipeline.SetImageArraySeparate(command._stage, command._setIndex, command._array.GetAs<ThreadedImageArray>(threaded)?.Base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Resources;
|
||||||
|
using Ryujinx.Graphics.Shader;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
||||||
|
{
|
||||||
|
struct SetTextureArraySeparateCommand : IGALCommand, IGALCommand<SetTextureArraySeparateCommand>
|
||||||
|
{
|
||||||
|
public readonly CommandType CommandType => CommandType.SetTextureArraySeparate;
|
||||||
|
private ShaderStage _stage;
|
||||||
|
private int _setIndex;
|
||||||
|
private TableRef<ITextureArray> _array;
|
||||||
|
|
||||||
|
public void Set(ShaderStage stage, int setIndex, TableRef<ITextureArray> array)
|
||||||
|
{
|
||||||
|
_stage = stage;
|
||||||
|
_setIndex = setIndex;
|
||||||
|
_array = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run(ref SetTextureArraySeparateCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||||
|
{
|
||||||
|
renderer.Pipeline.SetTextureArraySeparate(command._stage, command._setIndex, command._array.GetAs<ThreadedTextureArray>(threaded)?.Base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
||||||
|
using Ryujinx.Graphics.GAL.Multithreading.Resources;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.GAL.Multithreading.Commands.TextureArray
|
||||||
|
{
|
||||||
|
struct TextureArrayDisposeCommand : IGALCommand, IGALCommand<TextureArrayDisposeCommand>
|
||||||
|
{
|
||||||
|
public readonly CommandType CommandType => CommandType.TextureArrayDispose;
|
||||||
|
private TableRef<ThreadedTextureArray> _textureArray;
|
||||||
|
|
||||||
|
public void Set(TableRef<ThreadedTextureArray> textureArray)
|
||||||
|
{
|
||||||
|
_textureArray = textureArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run(ref TextureArrayDisposeCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||||
|
{
|
||||||
|
command._textureArray.Get(threaded).Base.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,12 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|||||||
return new TableRef<T>(_renderer, reference);
|
return new TableRef<T>(_renderer, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_renderer.New<ImageArrayDisposeCommand>().Set(Ref(this));
|
||||||
|
_renderer.QueueCommand();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetFormats(int index, Format[] imageFormats)
|
public void SetFormats(int index, Format[] imageFormats)
|
||||||
{
|
{
|
||||||
_renderer.New<ImageArraySetFormatsCommand>().Set(Ref(this), index, Ref(imageFormats));
|
_renderer.New<ImageArraySetFormatsCommand>().Set(Ref(this), index, Ref(imageFormats));
|
||||||
|
@ -22,6 +22,12 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|||||||
return new TableRef<T>(_renderer, reference);
|
return new TableRef<T>(_renderer, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_renderer.New<TextureArrayDisposeCommand>().Set(Ref(this));
|
||||||
|
_renderer.QueueCommand();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetSamplers(int index, ISampler[] samplers)
|
public void SetSamplers(int index, ISampler[] samplers)
|
||||||
{
|
{
|
||||||
_renderer.New<TextureArraySetSamplersCommand>().Set(Ref(this), index, Ref(samplers.ToArray()));
|
_renderer.New<TextureArraySetSamplersCommand>().Set(Ref(this), index, Ref(samplers.ToArray()));
|
||||||
|
@ -189,6 +189,12 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
_renderer.QueueCommand();
|
_renderer.QueueCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetImageArraySeparate(ShaderStage stage, int setIndex, IImageArray array)
|
||||||
|
{
|
||||||
|
_renderer.New<SetImageArraySeparateCommand>().Set(stage, setIndex, Ref(array));
|
||||||
|
_renderer.QueueCommand();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
||||||
{
|
{
|
||||||
_renderer.New<SetIndexBufferCommand>().Set(buffer, type);
|
_renderer.New<SetIndexBufferCommand>().Set(buffer, type);
|
||||||
@ -297,6 +303,12 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||||||
_renderer.QueueCommand();
|
_renderer.QueueCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTextureArraySeparate(ShaderStage stage, int setIndex, ITextureArray array)
|
||||||
|
{
|
||||||
|
_renderer.New<SetTextureArraySeparateCommand>().Set(stage, setIndex, Ref(array));
|
||||||
|
_renderer.QueueCommand();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
||||||
{
|
{
|
||||||
_renderer.New<SetTransformFeedbackBuffersCommand>().Set(_renderer.CopySpan(buffers));
|
_renderer.New<SetTransformFeedbackBuffersCommand>().Set(_renderer.CopySpan(buffers));
|
||||||
|
@ -74,13 +74,15 @@ namespace Ryujinx.Graphics.GAL
|
|||||||
public int ArrayLength { get; }
|
public int ArrayLength { get; }
|
||||||
public ResourceType Type { get; }
|
public ResourceType Type { get; }
|
||||||
public ResourceStages Stages { get; }
|
public ResourceStages Stages { get; }
|
||||||
|
public bool Write { get; }
|
||||||
|
|
||||||
public ResourceUsage(int binding, int arrayLength, ResourceType type, ResourceStages stages)
|
public ResourceUsage(int binding, int arrayLength, ResourceType type, ResourceStages stages, bool write)
|
||||||
{
|
{
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
ArrayLength = arrayLength;
|
ArrayLength = arrayLength;
|
||||||
Type = type;
|
Type = type;
|
||||||
Stages = stages;
|
Stages = stages;
|
||||||
|
Write = write;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
|
@ -199,7 +199,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
|
|||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
target.SynchronizeMemory();
|
target.SynchronizeMemory();
|
||||||
var dataCopy = ByteMemoryPool.RentCopy(data);
|
var dataCopy = MemoryOwner<byte>.RentCopy(data);
|
||||||
target.SetData(dataCopy, 0, 0, new GAL.Rectangle<int>(_dstX, _dstY, _lineLengthIn / target.Info.FormatInfo.BytesPerPixel, _lineCount));
|
target.SetData(dataCopy, 0, 0, new GAL.Rectangle<int>(_dstX, _dstY, _lineLengthIn / target.Info.FormatInfo.BytesPerPixel, _lineCount));
|
||||||
target.SignalModified();
|
target.SignalModified();
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
|
using Ryujinx.Common.Memory;
|
||||||
using Ryujinx.Graphics.GAL;
|
using Ryujinx.Graphics.GAL;
|
||||||
using Ryujinx.Graphics.Gpu.Memory;
|
using Ryujinx.Graphics.Gpu.Memory;
|
||||||
using Ryujinx.Graphics.Texture;
|
using Ryujinx.Graphics.Texture;
|
||||||
@ -805,7 +806,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
sliceDepth,
|
sliceDepth,
|
||||||
levels,
|
levels,
|
||||||
layers,
|
layers,
|
||||||
out IMemoryOwner<byte> decoded))
|
out MemoryOwner<byte> decoded))
|
||||||
{
|
{
|
||||||
string texInfo = $"{Info.Target} {Info.FormatInfo.Format} {Info.Width}x{Info.Height}x{Info.DepthOrLayers} levels {Info.Levels}";
|
string texInfo = $"{Info.Target} {Info.FormatInfo.Format} {Info.Width}x{Info.Height}x{Info.DepthOrLayers} levels {Info.Levels}";
|
||||||
|
|
||||||
|
@ -19,6 +19,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Format Format { get; }
|
public Format Format { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shader texture host set index.
|
||||||
|
/// </summary>
|
||||||
|
public int Set { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shader texture host binding point.
|
/// Shader texture host binding point.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,15 +59,17 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="target">The shader sampler target type</param>
|
/// <param name="target">The shader sampler target type</param>
|
||||||
/// <param name="format">Format of the image as declared on the shader</param>
|
/// <param name="format">Format of the image as declared on the shader</param>
|
||||||
|
/// <param name="set">Shader texture host set index</param>
|
||||||
/// <param name="binding">The shader texture binding point</param>
|
/// <param name="binding">The shader texture binding point</param>
|
||||||
/// <param name="arrayLength">For array of textures, this indicates the length of the array. A value of one indicates it is not an array</param>
|
/// <param name="arrayLength">For array of textures, this indicates the length of the array. A value of one indicates it is not an array</param>
|
||||||
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
|
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
|
||||||
/// <param name="handle">The shader texture handle (read index into the texture constant buffer)</param>
|
/// <param name="handle">The shader texture handle (read index into the texture constant buffer)</param>
|
||||||
/// <param name="flags">The texture's usage flags, indicating how it is used in the shader</param>
|
/// <param name="flags">The texture's usage flags, indicating how it is used in the shader</param>
|
||||||
public TextureBindingInfo(Target target, Format format, int binding, int arrayLength, int cbufSlot, int handle, TextureUsageFlags flags)
|
public TextureBindingInfo(Target target, Format format, int set, int binding, int arrayLength, int cbufSlot, int handle, TextureUsageFlags flags)
|
||||||
{
|
{
|
||||||
Target = target;
|
Target = target;
|
||||||
Format = format;
|
Format = format;
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
ArrayLength = arrayLength;
|
ArrayLength = arrayLength;
|
||||||
CbufSlot = cbufSlot;
|
CbufSlot = cbufSlot;
|
||||||
@ -74,6 +81,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// Constructs the texture binding information structure.
|
/// Constructs the texture binding information structure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="target">The shader sampler target type</param>
|
/// <param name="target">The shader sampler target type</param>
|
||||||
|
/// <param name="set">Shader texture host set index</param>
|
||||||
/// <param name="binding">The shader texture binding point</param>
|
/// <param name="binding">The shader texture binding point</param>
|
||||||
/// <param name="arrayLength">For array of textures, this indicates the length of the array. A value of one indicates it is not an array</param>
|
/// <param name="arrayLength">For array of textures, this indicates the length of the array. A value of one indicates it is not an array</param>
|
||||||
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
|
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
|
||||||
@ -82,12 +90,13 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// <param name="isSamplerOnly">Indicates that the binding is for a sampler</param>
|
/// <param name="isSamplerOnly">Indicates that the binding is for a sampler</param>
|
||||||
public TextureBindingInfo(
|
public TextureBindingInfo(
|
||||||
Target target,
|
Target target,
|
||||||
|
int set,
|
||||||
int binding,
|
int binding,
|
||||||
int arrayLength,
|
int arrayLength,
|
||||||
int cbufSlot,
|
int cbufSlot,
|
||||||
int handle,
|
int handle,
|
||||||
TextureUsageFlags flags,
|
TextureUsageFlags flags,
|
||||||
bool isSamplerOnly) : this(target, 0, binding, arrayLength, cbufSlot, handle, flags)
|
bool isSamplerOnly) : this(target, 0, set, binding, arrayLength, cbufSlot, handle, flags)
|
||||||
{
|
{
|
||||||
IsSamplerOnly = isSamplerOnly;
|
IsSamplerOnly = isSamplerOnly;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
int stageIndex,
|
int stageIndex,
|
||||||
int textureBufferIndex,
|
int textureBufferIndex,
|
||||||
SamplerIndex samplerIndex,
|
SamplerIndex samplerIndex,
|
||||||
TextureBindingInfo bindingInfo)
|
in TextureBindingInfo bindingInfo)
|
||||||
{
|
{
|
||||||
Update(texturePool, samplerPool, stage, stageIndex, textureBufferIndex, isImage: false, samplerIndex, bindingInfo);
|
Update(texturePool, samplerPool, stage, stageIndex, textureBufferIndex, isImage: false, samplerIndex, bindingInfo);
|
||||||
}
|
}
|
||||||
@ -579,7 +579,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// <param name="stageIndex">Shader stage index where the array is used</param>
|
/// <param name="stageIndex">Shader stage index where the array is used</param>
|
||||||
/// <param name="textureBufferIndex">Texture constant buffer index</param>
|
/// <param name="textureBufferIndex">Texture constant buffer index</param>
|
||||||
/// <param name="bindingInfo">Array binding information</param>
|
/// <param name="bindingInfo">Array binding information</param>
|
||||||
public void UpdateImageArray(TexturePool texturePool, ShaderStage stage, int stageIndex, int textureBufferIndex, TextureBindingInfo bindingInfo)
|
public void UpdateImageArray(TexturePool texturePool, ShaderStage stage, int stageIndex, int textureBufferIndex, in TextureBindingInfo bindingInfo)
|
||||||
{
|
{
|
||||||
Update(texturePool, null, stage, stageIndex, textureBufferIndex, isImage: true, SamplerIndex.ViaHeaderIndex, bindingInfo);
|
Update(texturePool, null, stage, stageIndex, textureBufferIndex, isImage: true, SamplerIndex.ViaHeaderIndex, bindingInfo);
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
int textureBufferIndex,
|
int textureBufferIndex,
|
||||||
bool isImage,
|
bool isImage,
|
||||||
SamplerIndex samplerIndex,
|
SamplerIndex samplerIndex,
|
||||||
TextureBindingInfo bindingInfo)
|
in TextureBindingInfo bindingInfo)
|
||||||
{
|
{
|
||||||
if (IsDirectHandleType(bindingInfo.Handle))
|
if (IsDirectHandleType(bindingInfo.Handle))
|
||||||
{
|
{
|
||||||
@ -623,7 +623,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// <param name="stage">Shader stage where the array is used</param>
|
/// <param name="stage">Shader stage where the array is used</param>
|
||||||
/// <param name="isImage">Whether the array is a image or texture array</param>
|
/// <param name="isImage">Whether the array is a image or texture array</param>
|
||||||
/// <param name="bindingInfo">Array binding information</param>
|
/// <param name="bindingInfo">Array binding information</param>
|
||||||
private void UpdateFromPool(TexturePool texturePool, SamplerPool samplerPool, ShaderStage stage, bool isImage, TextureBindingInfo bindingInfo)
|
private void UpdateFromPool(TexturePool texturePool, SamplerPool samplerPool, ShaderStage stage, bool isImage, in TextureBindingInfo bindingInfo)
|
||||||
{
|
{
|
||||||
CacheEntry entry = GetOrAddEntry(texturePool, samplerPool, bindingInfo, isImage, out bool isNewEntry);
|
CacheEntry entry = GetOrAddEntry(texturePool, samplerPool, bindingInfo, isImage, out bool isNewEntry);
|
||||||
|
|
||||||
@ -638,11 +638,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
|
|
||||||
if (isImage)
|
if (isImage)
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
SetImageArray(stage, bindingInfo, entry.ImageArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
SetTextureArray(stage, bindingInfo, entry.TextureArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -737,14 +737,14 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
entry.ImageArray.SetFormats(0, formats);
|
entry.ImageArray.SetFormats(0, formats);
|
||||||
entry.ImageArray.SetImages(0, textures);
|
entry.ImageArray.SetImages(0, textures);
|
||||||
|
|
||||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
SetImageArray(stage, bindingInfo, entry.ImageArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entry.TextureArray.SetSamplers(0, samplers);
|
entry.TextureArray.SetSamplers(0, samplers);
|
||||||
entry.TextureArray.SetTextures(0, textures);
|
entry.TextureArray.SetTextures(0, textures);
|
||||||
|
|
||||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
SetTextureArray(stage, bindingInfo, entry.TextureArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,7 +767,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
int textureBufferIndex,
|
int textureBufferIndex,
|
||||||
bool isImage,
|
bool isImage,
|
||||||
SamplerIndex samplerIndex,
|
SamplerIndex samplerIndex,
|
||||||
TextureBindingInfo bindingInfo)
|
in TextureBindingInfo bindingInfo)
|
||||||
{
|
{
|
||||||
(textureBufferIndex, int samplerBufferIndex) = TextureHandle.UnpackSlots(bindingInfo.CbufSlot, textureBufferIndex);
|
(textureBufferIndex, int samplerBufferIndex) = TextureHandle.UnpackSlots(bindingInfo.CbufSlot, textureBufferIndex);
|
||||||
|
|
||||||
@ -800,11 +800,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
|
|
||||||
if (isImage)
|
if (isImage)
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
SetImageArray(stage, bindingInfo, entry.ImageArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
SetTextureArray(stage, bindingInfo, entry.TextureArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -829,11 +829,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
|
|
||||||
if (isImage)
|
if (isImage)
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
SetImageArray(stage, bindingInfo, entry.ImageArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
SetTextureArray(stage, bindingInfo, entry.TextureArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -950,14 +950,50 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
entry.ImageArray.SetFormats(0, formats);
|
entry.ImageArray.SetFormats(0, formats);
|
||||||
entry.ImageArray.SetImages(0, textures);
|
entry.ImageArray.SetImages(0, textures);
|
||||||
|
|
||||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
SetImageArray(stage, bindingInfo, entry.ImageArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entry.TextureArray.SetSamplers(0, samplers);
|
entry.TextureArray.SetSamplers(0, samplers);
|
||||||
entry.TextureArray.SetTextures(0, textures);
|
entry.TextureArray.SetTextures(0, textures);
|
||||||
|
|
||||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
SetTextureArray(stage, bindingInfo, entry.TextureArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a texture array binding on the host.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stage">Shader stage where the array is used</param>
|
||||||
|
/// <param name="bindingInfo">Array binding information</param>
|
||||||
|
/// <param name="array">Texture array</param>
|
||||||
|
private void SetTextureArray(ShaderStage stage, in TextureBindingInfo bindingInfo, ITextureArray array)
|
||||||
|
{
|
||||||
|
if (bindingInfo.Set >= _context.Capabilities.ExtraSetBaseIndex && _context.Capabilities.MaximumExtraSets != 0)
|
||||||
|
{
|
||||||
|
_context.Renderer.Pipeline.SetTextureArraySeparate(stage, bindingInfo.Set, array);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a image array binding on the host.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stage">Shader stage where the array is used</param>
|
||||||
|
/// <param name="bindingInfo">Array binding information</param>
|
||||||
|
/// <param name="array">Image array</param>
|
||||||
|
private void SetImageArray(ShaderStage stage, in TextureBindingInfo bindingInfo, IImageArray array)
|
||||||
|
{
|
||||||
|
if (bindingInfo.Set >= _context.Capabilities.ExtraSetBaseIndex && _context.Capabilities.MaximumExtraSets != 0)
|
||||||
|
{
|
||||||
|
_context.Renderer.Pipeline.SetImageArraySeparate(stage, bindingInfo.Set, array);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,7 +1009,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
private CacheEntry GetOrAddEntry(
|
private CacheEntry GetOrAddEntry(
|
||||||
TexturePool texturePool,
|
TexturePool texturePool,
|
||||||
SamplerPool samplerPool,
|
SamplerPool samplerPool,
|
||||||
TextureBindingInfo bindingInfo,
|
in TextureBindingInfo bindingInfo,
|
||||||
bool isImage,
|
bool isImage,
|
||||||
out bool isNew)
|
out bool isNew)
|
||||||
{
|
{
|
||||||
@ -1015,7 +1051,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
private CacheEntryFromBuffer GetOrAddEntry(
|
private CacheEntryFromBuffer GetOrAddEntry(
|
||||||
TexturePool texturePool,
|
TexturePool texturePool,
|
||||||
SamplerPool samplerPool,
|
SamplerPool samplerPool,
|
||||||
TextureBindingInfo bindingInfo,
|
in TextureBindingInfo bindingInfo,
|
||||||
bool isImage,
|
bool isImage,
|
||||||
ref BufferBounds textureBufferBounds,
|
ref BufferBounds textureBufferBounds,
|
||||||
out bool isNew)
|
out bool isNew)
|
||||||
@ -1077,6 +1113,15 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
nextNode = nextNode.Next;
|
nextNode = nextNode.Next;
|
||||||
_cacheFromBuffer.Remove(toRemove.Value.Key);
|
_cacheFromBuffer.Remove(toRemove.Value.Key);
|
||||||
_lruCache.Remove(toRemove);
|
_lruCache.Remove(toRemove);
|
||||||
|
|
||||||
|
if (toRemove.Value.Key.IsImage)
|
||||||
|
{
|
||||||
|
toRemove.Value.ImageArray.Dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toRemove.Value.TextureArray.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,11 +1133,20 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
{
|
{
|
||||||
List<CacheEntryFromPoolKey> keysToRemove = null;
|
List<CacheEntryFromPoolKey> keysToRemove = null;
|
||||||
|
|
||||||
foreach (CacheEntryFromPoolKey key in _cacheFromPool.Keys)
|
foreach ((CacheEntryFromPoolKey key, CacheEntry entry) in _cacheFromPool)
|
||||||
{
|
{
|
||||||
if (key.MatchesPool(pool))
|
if (key.MatchesPool(pool))
|
||||||
{
|
{
|
||||||
(keysToRemove ??= new()).Add(key);
|
(keysToRemove ??= new()).Add(key);
|
||||||
|
|
||||||
|
if (key.IsImage)
|
||||||
|
{
|
||||||
|
entry.ImageArray.Dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry.TextureArray.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ using Ryujinx.Common.Memory;
|
|||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
using Ryujinx.Memory.Range;
|
using Ryujinx.Memory.Range;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -242,9 +241,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> memoryOwner = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> memoryOwner = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
GetSpan(va, size).CopyTo(memoryOwner.Memory.Span);
|
ReadImpl(va, memoryOwner.Span, tracked);
|
||||||
|
|
||||||
return new WritableRegion(this, va, memoryOwner, tracked);
|
return new WritableRegion(this, va, memoryOwner, tracked);
|
||||||
}
|
}
|
||||||
|
@ -192,9 +192,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> memoryOwner = ByteMemoryPool.Rent(range.GetSize());
|
MemoryOwner<byte> memoryOwner = MemoryOwner<byte>.Rent(checked((int)range.GetSize()));
|
||||||
|
|
||||||
Memory<byte> memory = memoryOwner.Memory;
|
Span<byte> memorySpan = memoryOwner.Span;
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (int i = 0; i < range.Count; i++)
|
for (int i = 0; i < range.Count; i++)
|
||||||
@ -203,7 +203,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||||||
int size = (int)currentRange.Size;
|
int size = (int)currentRange.Size;
|
||||||
if (currentRange.Address != MemoryManager.PteUnmapped)
|
if (currentRange.Address != MemoryManager.PteUnmapped)
|
||||||
{
|
{
|
||||||
GetSpan(currentRange.Address, size).CopyTo(memory.Span.Slice(offset, size));
|
GetSpan(currentRange.Address, size).CopyTo(memorySpan.Slice(offset, size));
|
||||||
}
|
}
|
||||||
offset += size;
|
offset += size;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
|
|
||||||
var result = new TextureBindingInfo(
|
var result = new TextureBindingInfo(
|
||||||
target,
|
target,
|
||||||
|
descriptor.Set,
|
||||||
descriptor.Binding,
|
descriptor.Binding,
|
||||||
descriptor.ArrayLength,
|
descriptor.ArrayLength,
|
||||||
descriptor.CbufSlot,
|
descriptor.CbufSlot,
|
||||||
@ -90,6 +91,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
var result = new TextureBindingInfo(
|
var result = new TextureBindingInfo(
|
||||||
target,
|
target,
|
||||||
format,
|
format,
|
||||||
|
descriptor.Set,
|
||||||
descriptor.Binding,
|
descriptor.Binding,
|
||||||
descriptor.ArrayLength,
|
descriptor.ArrayLength,
|
||||||
descriptor.CbufSlot,
|
descriptor.CbufSlot,
|
||||||
|
@ -125,9 +125,18 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
CompressionAlgorithm algorithm = CompressionAlgorithm.None;
|
CompressionAlgorithm algorithm = CompressionAlgorithm.None;
|
||||||
Read(ref algorithm);
|
Read(ref algorithm);
|
||||||
|
|
||||||
if (algorithm == CompressionAlgorithm.Deflate)
|
switch (algorithm)
|
||||||
{
|
{
|
||||||
_activeStream = new DeflateStream(_stream, CompressionMode.Decompress, true);
|
case CompressionAlgorithm.None:
|
||||||
|
break;
|
||||||
|
case CompressionAlgorithm.Deflate:
|
||||||
|
_activeStream = new DeflateStream(_stream, CompressionMode.Decompress, true);
|
||||||
|
break;
|
||||||
|
case CompressionAlgorithm.Brotli:
|
||||||
|
_activeStream = new BrotliStream(_stream, CompressionMode.Decompress, true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException($"Invalid compression algorithm \"{algorithm}\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +148,18 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
{
|
{
|
||||||
Write(ref algorithm);
|
Write(ref algorithm);
|
||||||
|
|
||||||
if (algorithm == CompressionAlgorithm.Deflate)
|
switch (algorithm)
|
||||||
{
|
{
|
||||||
_activeStream = new DeflateStream(_stream, CompressionLevel.Fastest, true);
|
case CompressionAlgorithm.None:
|
||||||
|
break;
|
||||||
|
case CompressionAlgorithm.Deflate:
|
||||||
|
_activeStream = new DeflateStream(_stream, CompressionLevel.Fastest, true);
|
||||||
|
break;
|
||||||
|
case CompressionAlgorithm.Brotli:
|
||||||
|
_activeStream = new BrotliStream(_stream, CompressionLevel.Fastest, true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException($"Invalid compression algorithm \"{algorithm}\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
switch (algorithm)
|
switch (algorithm)
|
||||||
{
|
{
|
||||||
case CompressionAlgorithm.None:
|
case CompressionAlgorithm.None:
|
||||||
stream.Read(data);
|
stream.ReadExactly(data);
|
||||||
break;
|
break;
|
||||||
case CompressionAlgorithm.Deflate:
|
case CompressionAlgorithm.Deflate:
|
||||||
stream = new DeflateStream(stream, CompressionMode.Decompress, true);
|
stream = new DeflateStream(stream, CompressionMode.Decompress, true);
|
||||||
@ -187,6 +205,14 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
}
|
}
|
||||||
stream.Dispose();
|
stream.Dispose();
|
||||||
break;
|
break;
|
||||||
|
case CompressionAlgorithm.Brotli:
|
||||||
|
stream = new BrotliStream(stream, CompressionMode.Decompress, true);
|
||||||
|
for (int offset = 0; offset < data.Length;)
|
||||||
|
{
|
||||||
|
offset += stream.Read(data[offset..]);
|
||||||
|
}
|
||||||
|
stream.Dispose();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +236,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
stream.Write(data);
|
stream.Write(data);
|
||||||
stream.Dispose();
|
stream.Dispose();
|
||||||
break;
|
break;
|
||||||
|
case CompressionAlgorithm.Brotli:
|
||||||
|
stream = new BrotliStream(stream, CompressionLevel.Fastest, true);
|
||||||
|
stream.Write(data);
|
||||||
|
stream.Dispose();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,10 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
/// Deflate compression (RFC 1951).
|
/// Deflate compression (RFC 1951).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Deflate,
|
Deflate,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Brotli compression (RFC 7932).
|
||||||
|
/// </summary>
|
||||||
|
Brotli,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
/// <returns>Compression algorithm</returns>
|
/// <returns>Compression algorithm</returns>
|
||||||
public static CompressionAlgorithm GetCompressionAlgorithm()
|
public static CompressionAlgorithm GetCompressionAlgorithm()
|
||||||
{
|
{
|
||||||
return CompressionAlgorithm.Deflate;
|
return CompressionAlgorithm.Brotli;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
dataFileStream.Seek((long)entry.Offset, SeekOrigin.Begin);
|
dataFileStream.Seek((long)entry.Offset, SeekOrigin.Begin);
|
||||||
dataFileStream.Read(cb1Data);
|
dataFileStream.ReadExactly(cb1Data);
|
||||||
BinarySerializer.ReadCompressed(dataFileStream, guestCode);
|
BinarySerializer.ReadCompressed(dataFileStream, guestCode);
|
||||||
|
|
||||||
_cache[index] = (guestCode, cb1Data);
|
_cache[index] = (guestCode, cb1Data);
|
||||||
@ -279,7 +279,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
dataFileStream.Seek((long)entry.Offset, SeekOrigin.Begin);
|
dataFileStream.Seek((long)entry.Offset, SeekOrigin.Begin);
|
||||||
byte[] cachedCode = new byte[entry.CodeSize];
|
byte[] cachedCode = new byte[entry.CodeSize];
|
||||||
byte[] cachedCb1Data = new byte[entry.Cb1DataSize];
|
byte[] cachedCb1Data = new byte[entry.Cb1DataSize];
|
||||||
dataFileStream.Read(cachedCb1Data);
|
dataFileStream.ReadExactly(cachedCb1Data);
|
||||||
BinarySerializer.ReadCompressed(dataFileStream, cachedCode);
|
BinarySerializer.ReadCompressed(dataFileStream, cachedCode);
|
||||||
|
|
||||||
if (data.SequenceEqual(cachedCode) && cb1Data.SequenceEqual(cachedCb1Data))
|
if (data.SequenceEqual(cachedCode) && cb1Data.SequenceEqual(cachedCb1Data))
|
||||||
|
@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|||||||
private const ushort FileFormatVersionMajor = 1;
|
private const ushort FileFormatVersionMajor = 1;
|
||||||
private const ushort FileFormatVersionMinor = 2;
|
private const ushort FileFormatVersionMinor = 2;
|
||||||
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
|
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
|
||||||
private const uint CodeGenVersion = 5936;
|
private const uint CodeGenVersion = 7131;
|
||||||
|
|
||||||
private const string SharedTocFileName = "shared.toc";
|
private const string SharedTocFileName = "shared.toc";
|
||||||
private const string SharedDataFileName = "shared.data";
|
private const string SharedDataFileName = "shared.data";
|
||||||
|
@ -51,7 +51,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
_reservedImages = rrc.ReservedImages;
|
_reservedImages = rrc.ReservedImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CreateConstantBufferBinding(int index)
|
public SetBindingPair CreateConstantBufferBinding(int index)
|
||||||
{
|
{
|
||||||
int binding;
|
int binding;
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
binding = _resourceCounts.UniformBuffersCount++;
|
binding = _resourceCounts.UniformBuffersCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding + _reservedConstantBuffers;
|
return new SetBindingPair(_context.Capabilities.UniformBufferSetIndex, binding + _reservedConstantBuffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CreateImageBinding(int count, bool isBuffer)
|
public SetBindingPair CreateImageBinding(int count, bool isBuffer)
|
||||||
{
|
{
|
||||||
int binding;
|
int binding;
|
||||||
|
|
||||||
@ -96,10 +96,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
_resourceCounts.ImagesCount += count;
|
_resourceCounts.ImagesCount += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding + _reservedImages;
|
return new SetBindingPair(_context.Capabilities.ImageSetIndex, binding + _reservedImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CreateStorageBufferBinding(int index)
|
public SetBindingPair CreateStorageBufferBinding(int index)
|
||||||
{
|
{
|
||||||
int binding;
|
int binding;
|
||||||
|
|
||||||
@ -112,10 +112,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
binding = _resourceCounts.StorageBuffersCount++;
|
binding = _resourceCounts.StorageBuffersCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding + _reservedStorageBuffers;
|
return new SetBindingPair(_context.Capabilities.StorageBufferSetIndex, binding + _reservedStorageBuffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CreateTextureBinding(int count, bool isBuffer)
|
public SetBindingPair CreateTextureBinding(int count, bool isBuffer)
|
||||||
{
|
{
|
||||||
int binding;
|
int binding;
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
_resourceCounts.TexturesCount += count;
|
_resourceCounts.TexturesCount += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding + _reservedTextures;
|
return new SetBindingPair(_context.Capabilities.TextureSetIndex, binding + _reservedTextures);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetBindingFromIndex(int index, uint maxPerStage, string resourceName)
|
private int GetBindingFromIndex(int index, uint maxPerStage, string resourceName)
|
||||||
@ -183,6 +183,16 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
return maxPerStage * Constants.ShaderStages;
|
return maxPerStage * Constants.ShaderStages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CreateExtraSet()
|
||||||
|
{
|
||||||
|
if (_resourceCounts.SetsCount >= _context.Capabilities.MaximumExtraSets)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _context.Capabilities.ExtraSetBaseIndex + _resourceCounts.SetsCount++;
|
||||||
|
}
|
||||||
|
|
||||||
public int QueryHostGatherBiasPrecision() => _context.Capabilities.GatherBiasPrecision;
|
public int QueryHostGatherBiasPrecision() => _context.Capabilities.GatherBiasPrecision;
|
||||||
|
|
||||||
public bool QueryHostReducedPrecision() => _context.Capabilities.ReduceShaderPrecision;
|
public bool QueryHostReducedPrecision() => _context.Capabilities.ReduceShaderPrecision;
|
||||||
|
@ -24,5 +24,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// Total of images used by the shaders.
|
/// Total of images used by the shaders.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ImagesCount;
|
public int ImagesCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total of extra sets used by the shaders.
|
||||||
|
/// </summary>
|
||||||
|
public int SetsCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Ryujinx.Graphics.GAL;
|
using Ryujinx.Graphics.GAL;
|
||||||
using Ryujinx.Graphics.Shader;
|
using Ryujinx.Graphics.Shader;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Gpu.Shader
|
namespace Ryujinx.Graphics.Gpu.Shader
|
||||||
@ -9,13 +10,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
class ShaderInfoBuilder
|
class ShaderInfoBuilder
|
||||||
{
|
{
|
||||||
private const int TotalSets = 4;
|
|
||||||
|
|
||||||
private const int UniformSetIndex = 0;
|
|
||||||
private const int StorageSetIndex = 1;
|
|
||||||
private const int TextureSetIndex = 2;
|
|
||||||
private const int ImageSetIndex = 3;
|
|
||||||
|
|
||||||
private const ResourceStages SupportBufferStages =
|
private const ResourceStages SupportBufferStages =
|
||||||
ResourceStages.Compute |
|
ResourceStages.Compute |
|
||||||
ResourceStages.Vertex |
|
ResourceStages.Vertex |
|
||||||
@ -36,8 +30,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
private readonly int _reservedTextures;
|
private readonly int _reservedTextures;
|
||||||
private readonly int _reservedImages;
|
private readonly int _reservedImages;
|
||||||
|
|
||||||
private readonly List<ResourceDescriptor>[] _resourceDescriptors;
|
private List<ResourceDescriptor>[] _resourceDescriptors;
|
||||||
private readonly List<ResourceUsage>[] _resourceUsages;
|
private List<ResourceUsage>[] _resourceUsages;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new shader info builder.
|
/// Creates a new shader info builder.
|
||||||
@ -51,17 +45,27 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
|
|
||||||
_fragmentOutputMap = -1;
|
_fragmentOutputMap = -1;
|
||||||
|
|
||||||
_resourceDescriptors = new List<ResourceDescriptor>[TotalSets];
|
int uniformSetIndex = context.Capabilities.UniformBufferSetIndex;
|
||||||
_resourceUsages = new List<ResourceUsage>[TotalSets];
|
int storageSetIndex = context.Capabilities.StorageBufferSetIndex;
|
||||||
|
int textureSetIndex = context.Capabilities.TextureSetIndex;
|
||||||
|
int imageSetIndex = context.Capabilities.ImageSetIndex;
|
||||||
|
|
||||||
for (int index = 0; index < TotalSets; index++)
|
int totalSets = Math.Max(uniformSetIndex, storageSetIndex);
|
||||||
|
totalSets = Math.Max(totalSets, textureSetIndex);
|
||||||
|
totalSets = Math.Max(totalSets, imageSetIndex);
|
||||||
|
totalSets++;
|
||||||
|
|
||||||
|
_resourceDescriptors = new List<ResourceDescriptor>[totalSets];
|
||||||
|
_resourceUsages = new List<ResourceUsage>[totalSets];
|
||||||
|
|
||||||
|
for (int index = 0; index < totalSets; index++)
|
||||||
{
|
{
|
||||||
_resourceDescriptors[index] = new();
|
_resourceDescriptors[index] = new();
|
||||||
_resourceUsages[index] = new();
|
_resourceUsages[index] = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
AddDescriptor(SupportBufferStages, ResourceType.UniformBuffer, UniformSetIndex, 0, 1);
|
AddDescriptor(SupportBufferStages, ResourceType.UniformBuffer, uniformSetIndex, 0, 1);
|
||||||
AddUsage(SupportBufferStages, ResourceType.UniformBuffer, UniformSetIndex, 0, 1);
|
AddUsage(SupportBufferStages, ResourceType.UniformBuffer, uniformSetIndex, 0, 1);
|
||||||
|
|
||||||
ResourceReservationCounts rrc = new(!context.Capabilities.SupportsTransformFeedback && tfEnabled, vertexAsCompute);
|
ResourceReservationCounts rrc = new(!context.Capabilities.SupportsTransformFeedback && tfEnabled, vertexAsCompute);
|
||||||
|
|
||||||
@ -73,16 +77,25 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
// TODO: Handle that better? Maybe we should only set the binding that are really needed on each shader.
|
// TODO: Handle that better? Maybe we should only set the binding that are really needed on each shader.
|
||||||
ResourceStages stages = vertexAsCompute ? ResourceStages.Compute | ResourceStages.Vertex : VtgStages;
|
ResourceStages stages = vertexAsCompute ? ResourceStages.Compute | ResourceStages.Vertex : VtgStages;
|
||||||
|
|
||||||
PopulateDescriptorAndUsages(stages, ResourceType.UniformBuffer, UniformSetIndex, 1, rrc.ReservedConstantBuffers - 1);
|
PopulateDescriptorAndUsages(stages, ResourceType.UniformBuffer, uniformSetIndex, 1, rrc.ReservedConstantBuffers - 1);
|
||||||
PopulateDescriptorAndUsages(stages, ResourceType.StorageBuffer, StorageSetIndex, 0, rrc.ReservedStorageBuffers);
|
PopulateDescriptorAndUsages(stages, ResourceType.StorageBuffer, storageSetIndex, 0, rrc.ReservedStorageBuffers, true);
|
||||||
PopulateDescriptorAndUsages(stages, ResourceType.BufferTexture, TextureSetIndex, 0, rrc.ReservedTextures);
|
PopulateDescriptorAndUsages(stages, ResourceType.BufferTexture, textureSetIndex, 0, rrc.ReservedTextures);
|
||||||
PopulateDescriptorAndUsages(stages, ResourceType.BufferImage, ImageSetIndex, 0, rrc.ReservedImages);
|
PopulateDescriptorAndUsages(stages, ResourceType.BufferImage, imageSetIndex, 0, rrc.ReservedImages, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateDescriptorAndUsages(ResourceStages stages, ResourceType type, int setIndex, int start, int count)
|
/// <summary>
|
||||||
|
/// Populates descriptors and usages for vertex as compute and transform feedback emulation reserved resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stages">Shader stages where the resources are used</param>
|
||||||
|
/// <param name="type">Resource type</param>
|
||||||
|
/// <param name="setIndex">Resource set index where the resources are used</param>
|
||||||
|
/// <param name="start">First binding number</param>
|
||||||
|
/// <param name="count">Amount of bindings</param>
|
||||||
|
/// <param name="write">True if the binding is written from the shader, false otherwise</param>
|
||||||
|
private void PopulateDescriptorAndUsages(ResourceStages stages, ResourceType type, int setIndex, int start, int count, bool write = false)
|
||||||
{
|
{
|
||||||
AddDescriptor(stages, type, setIndex, start, count);
|
AddDescriptor(stages, type, setIndex, start, count);
|
||||||
AddUsage(stages, type, setIndex, start, count);
|
AddUsage(stages, type, setIndex, start, count, write);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -127,18 +140,23 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
int textureBinding = _reservedTextures + stageIndex * texturesPerStage * 2;
|
int textureBinding = _reservedTextures + stageIndex * texturesPerStage * 2;
|
||||||
int imageBinding = _reservedImages + stageIndex * imagesPerStage * 2;
|
int imageBinding = _reservedImages + stageIndex * imagesPerStage * 2;
|
||||||
|
|
||||||
AddDescriptor(stages, ResourceType.UniformBuffer, UniformSetIndex, uniformBinding, uniformsPerStage);
|
int uniformSetIndex = _context.Capabilities.UniformBufferSetIndex;
|
||||||
AddDescriptor(stages, ResourceType.StorageBuffer, StorageSetIndex, storageBinding, storagesPerStage);
|
int storageSetIndex = _context.Capabilities.StorageBufferSetIndex;
|
||||||
AddDualDescriptor(stages, ResourceType.TextureAndSampler, ResourceType.BufferTexture, TextureSetIndex, textureBinding, texturesPerStage);
|
int textureSetIndex = _context.Capabilities.TextureSetIndex;
|
||||||
AddDualDescriptor(stages, ResourceType.Image, ResourceType.BufferImage, ImageSetIndex, imageBinding, imagesPerStage);
|
int imageSetIndex = _context.Capabilities.ImageSetIndex;
|
||||||
|
|
||||||
AddArrayDescriptors(info.Textures, stages, TextureSetIndex, isImage: false);
|
AddDescriptor(stages, ResourceType.UniformBuffer, uniformSetIndex, uniformBinding, uniformsPerStage);
|
||||||
AddArrayDescriptors(info.Images, stages, TextureSetIndex, isImage: true);
|
AddDescriptor(stages, ResourceType.StorageBuffer, storageSetIndex, storageBinding, storagesPerStage);
|
||||||
|
AddDualDescriptor(stages, ResourceType.TextureAndSampler, ResourceType.BufferTexture, textureSetIndex, textureBinding, texturesPerStage);
|
||||||
|
AddDualDescriptor(stages, ResourceType.Image, ResourceType.BufferImage, imageSetIndex, imageBinding, imagesPerStage);
|
||||||
|
|
||||||
AddUsage(info.CBuffers, stages, UniformSetIndex, isStorage: false);
|
AddArrayDescriptors(info.Textures, stages, isImage: false);
|
||||||
AddUsage(info.SBuffers, stages, StorageSetIndex, isStorage: true);
|
AddArrayDescriptors(info.Images, stages, isImage: true);
|
||||||
AddUsage(info.Textures, stages, TextureSetIndex, isImage: false);
|
|
||||||
AddUsage(info.Images, stages, ImageSetIndex, isImage: true);
|
AddUsage(info.CBuffers, stages, isStorage: false);
|
||||||
|
AddUsage(info.SBuffers, stages, isStorage: true);
|
||||||
|
AddUsage(info.Textures, stages, isImage: false);
|
||||||
|
AddUsage(info.Images, stages, isImage: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -177,9 +195,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="textures">Textures to be added</param>
|
/// <param name="textures">Textures to be added</param>
|
||||||
/// <param name="stages">Stages where the textures are used</param>
|
/// <param name="stages">Stages where the textures are used</param>
|
||||||
/// <param name="setIndex">Descriptor set index where the textures will be bound</param>
|
|
||||||
/// <param name="isImage">True for images, false for textures</param>
|
/// <param name="isImage">True for images, false for textures</param>
|
||||||
private void AddArrayDescriptors(IEnumerable<TextureDescriptor> textures, ResourceStages stages, int setIndex, bool isImage)
|
private void AddArrayDescriptors(IEnumerable<TextureDescriptor> textures, ResourceStages stages, bool isImage)
|
||||||
{
|
{
|
||||||
foreach (TextureDescriptor texture in textures)
|
foreach (TextureDescriptor texture in textures)
|
||||||
{
|
{
|
||||||
@ -187,7 +204,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
{
|
{
|
||||||
ResourceType type = GetTextureResourceType(texture, isImage);
|
ResourceType type = GetTextureResourceType(texture, isImage);
|
||||||
|
|
||||||
_resourceDescriptors[setIndex].Add(new ResourceDescriptor(texture.Binding, texture.ArrayLength, type, stages));
|
GetDescriptors(texture.Set).Add(new ResourceDescriptor(texture.Binding, texture.ArrayLength, type, stages));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,11 +217,12 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// <param name="setIndex">Descriptor set number where the resource will be bound</param>
|
/// <param name="setIndex">Descriptor set number where the resource will be bound</param>
|
||||||
/// <param name="binding">Binding number where the resource will be bound</param>
|
/// <param name="binding">Binding number where the resource will be bound</param>
|
||||||
/// <param name="count">Number of resources bound at the binding location</param>
|
/// <param name="count">Number of resources bound at the binding location</param>
|
||||||
private void AddUsage(ResourceStages stages, ResourceType type, int setIndex, int binding, int count)
|
/// <param name="write">True if the binding is written from the shader, false otherwise</param>
|
||||||
|
private void AddUsage(ResourceStages stages, ResourceType type, int setIndex, int binding, int count, bool write = false)
|
||||||
{
|
{
|
||||||
for (int index = 0; index < count; index++)
|
for (int index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
_resourceUsages[setIndex].Add(new ResourceUsage(binding + index, 1, type, stages));
|
_resourceUsages[setIndex].Add(new ResourceUsage(binding + index, 1, type, stages, write));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,17 +231,17 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="buffers">Buffers to be added</param>
|
/// <param name="buffers">Buffers to be added</param>
|
||||||
/// <param name="stages">Stages where the buffers are used</param>
|
/// <param name="stages">Stages where the buffers are used</param>
|
||||||
/// <param name="setIndex">Descriptor set index where the buffers will be bound</param>
|
|
||||||
/// <param name="isStorage">True for storage buffers, false for uniform buffers</param>
|
/// <param name="isStorage">True for storage buffers, false for uniform buffers</param>
|
||||||
private void AddUsage(IEnumerable<BufferDescriptor> buffers, ResourceStages stages, int setIndex, bool isStorage)
|
private void AddUsage(IEnumerable<BufferDescriptor> buffers, ResourceStages stages, bool isStorage)
|
||||||
{
|
{
|
||||||
foreach (BufferDescriptor buffer in buffers)
|
foreach (BufferDescriptor buffer in buffers)
|
||||||
{
|
{
|
||||||
_resourceUsages[setIndex].Add(new ResourceUsage(
|
GetUsages(buffer.Set).Add(new ResourceUsage(
|
||||||
buffer.Binding,
|
buffer.Binding,
|
||||||
1,
|
1,
|
||||||
isStorage ? ResourceType.StorageBuffer : ResourceType.UniformBuffer,
|
isStorage ? ResourceType.StorageBuffer : ResourceType.UniformBuffer,
|
||||||
stages));
|
stages,
|
||||||
|
buffer.Flags.HasFlag(BufferUsageFlags.Write)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,18 +250,70 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="textures">Textures to be added</param>
|
/// <param name="textures">Textures to be added</param>
|
||||||
/// <param name="stages">Stages where the textures are used</param>
|
/// <param name="stages">Stages where the textures are used</param>
|
||||||
/// <param name="setIndex">Descriptor set index where the textures will be bound</param>
|
|
||||||
/// <param name="isImage">True for images, false for textures</param>
|
/// <param name="isImage">True for images, false for textures</param>
|
||||||
private void AddUsage(IEnumerable<TextureDescriptor> textures, ResourceStages stages, int setIndex, bool isImage)
|
private void AddUsage(IEnumerable<TextureDescriptor> textures, ResourceStages stages, bool isImage)
|
||||||
{
|
{
|
||||||
foreach (TextureDescriptor texture in textures)
|
foreach (TextureDescriptor texture in textures)
|
||||||
{
|
{
|
||||||
ResourceType type = GetTextureResourceType(texture, isImage);
|
ResourceType type = GetTextureResourceType(texture, isImage);
|
||||||
|
|
||||||
_resourceUsages[setIndex].Add(new ResourceUsage(texture.Binding, texture.ArrayLength, type, stages));
|
GetUsages(texture.Set).Add(new ResourceUsage(
|
||||||
|
texture.Binding,
|
||||||
|
texture.ArrayLength,
|
||||||
|
type,
|
||||||
|
stages,
|
||||||
|
texture.Flags.HasFlag(TextureUsageFlags.ImageStore)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of resource descriptors for a given set index. A new list will be created if needed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="setIndex">Resource set index</param>
|
||||||
|
/// <returns>List of resource descriptors</returns>
|
||||||
|
private List<ResourceDescriptor> GetDescriptors(int setIndex)
|
||||||
|
{
|
||||||
|
if (_resourceDescriptors.Length <= setIndex)
|
||||||
|
{
|
||||||
|
int oldLength = _resourceDescriptors.Length;
|
||||||
|
Array.Resize(ref _resourceDescriptors, setIndex + 1);
|
||||||
|
|
||||||
|
for (int index = oldLength; index <= setIndex; index++)
|
||||||
|
{
|
||||||
|
_resourceDescriptors[index] = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _resourceDescriptors[setIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of resource usages for a given set index. A new list will be created if needed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="setIndex">Resource set index</param>
|
||||||
|
/// <returns>List of resource usages</returns>
|
||||||
|
private List<ResourceUsage> GetUsages(int setIndex)
|
||||||
|
{
|
||||||
|
if (_resourceUsages.Length <= setIndex)
|
||||||
|
{
|
||||||
|
int oldLength = _resourceUsages.Length;
|
||||||
|
Array.Resize(ref _resourceUsages, setIndex + 1);
|
||||||
|
|
||||||
|
for (int index = oldLength; index <= setIndex; index++)
|
||||||
|
{
|
||||||
|
_resourceUsages[index] = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _resourceUsages[setIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a resource type from a texture descriptor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture">Texture descriptor</param>
|
||||||
|
/// <param name="isImage">Whether the texture is a image texture (writable) or not (sampled)</param>
|
||||||
|
/// <returns>Resource type</returns>
|
||||||
private static ResourceType GetTextureResourceType(TextureDescriptor texture, bool isImage)
|
private static ResourceType GetTextureResourceType(TextureDescriptor texture, bool isImage)
|
||||||
{
|
{
|
||||||
bool isBuffer = (texture.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
bool isBuffer = (texture.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
||||||
@ -278,10 +348,12 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||||||
/// <returns>Shader information</returns>
|
/// <returns>Shader information</returns>
|
||||||
public ShaderInfo Build(ProgramPipelineState? pipeline, bool fromCache = false)
|
public ShaderInfo Build(ProgramPipelineState? pipeline, bool fromCache = false)
|
||||||
{
|
{
|
||||||
var descriptors = new ResourceDescriptorCollection[TotalSets];
|
int totalSets = _resourceDescriptors.Length;
|
||||||
var usages = new ResourceUsageCollection[TotalSets];
|
|
||||||
|
|
||||||
for (int index = 0; index < TotalSets; index++)
|
var descriptors = new ResourceDescriptorCollection[totalSets];
|
||||||
|
var usages = new ResourceUsageCollection[totalSets];
|
||||||
|
|
||||||
|
for (int index = 0; index < totalSets; index++)
|
||||||
{
|
{
|
||||||
descriptors[index] = new ResourceDescriptorCollection(_resourceDescriptors[index].ToArray().AsReadOnly());
|
descriptors[index] = new ResourceDescriptorCollection(_resourceDescriptors[index].ToArray().AsReadOnly());
|
||||||
usages[index] = new ResourceUsageCollection(_resourceUsages[index].ToArray().AsReadOnly());
|
usages[index] = new ResourceUsageCollection(_resourceUsages[index].ToArray().AsReadOnly());
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
@ -10,11 +9,11 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||||||
{
|
{
|
||||||
static class FormatConverter
|
static class FormatConverter
|
||||||
{
|
{
|
||||||
public unsafe static IMemoryOwner<byte> ConvertS8D24ToD24S8(ReadOnlySpan<byte> data)
|
public unsafe static MemoryOwner<byte> ConvertS8D24ToD24S8(ReadOnlySpan<byte> data)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> outputMemory = ByteMemoryPool.Rent(data.Length);
|
MemoryOwner<byte> outputMemory = MemoryOwner<byte>.Rent(data.Length);
|
||||||
|
|
||||||
Span<byte> output = outputMemory.Memory.Span;
|
Span<byte> output = outputMemory.Span;
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
|
@ -63,5 +63,9 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,5 +48,9 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,12 @@ namespace Ryujinx.Graphics.OpenGL
|
|||||||
supportsViewportSwizzle: HwCapabilities.SupportsViewportSwizzle,
|
supportsViewportSwizzle: HwCapabilities.SupportsViewportSwizzle,
|
||||||
supportsIndirectParameters: HwCapabilities.SupportsIndirectParameters,
|
supportsIndirectParameters: HwCapabilities.SupportsIndirectParameters,
|
||||||
supportsDepthClipControl: true,
|
supportsDepthClipControl: true,
|
||||||
|
uniformBufferSetIndex: 0,
|
||||||
|
storageBufferSetIndex: 1,
|
||||||
|
textureSetIndex: 2,
|
||||||
|
imageSetIndex: 3,
|
||||||
|
extraSetBaseIndex: 0,
|
||||||
|
maximumExtraSets: 0,
|
||||||
maximumUniformBuffersPerStage: 13, // TODO: Avoid hardcoding those limits here and get from driver?
|
maximumUniformBuffersPerStage: 13, // TODO: Avoid hardcoding those limits here and get from driver?
|
||||||
maximumStorageBuffersPerStage: 16,
|
maximumStorageBuffersPerStage: 16,
|
||||||
maximumTexturesPerStage: 32,
|
maximumTexturesPerStage: 32,
|
||||||
|
@ -963,6 +963,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|||||||
(array as ImageArray).Bind(binding);
|
(array as ImageArray).Bind(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetImageArraySeparate(ShaderStage stage, int setIndex, IImageArray array)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("OpenGL does not support descriptor sets.");
|
||||||
|
}
|
||||||
|
|
||||||
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
||||||
{
|
{
|
||||||
_elementsType = type.Convert();
|
_elementsType = type.Convert();
|
||||||
@ -1312,6 +1317,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|||||||
(array as TextureArray).Bind(binding);
|
(array as TextureArray).Bind(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTextureArraySeparate(ShaderStage stage, int setIndex, ITextureArray array)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("OpenGL does not support descriptor sets.");
|
||||||
|
}
|
||||||
|
|
||||||
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
||||||
{
|
{
|
||||||
if (_tfEnabled)
|
if (_tfEnabled)
|
||||||
|
@ -4,14 +4,16 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
{
|
{
|
||||||
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
|
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
|
||||||
|
|
||||||
|
public readonly int Set;
|
||||||
public readonly int Binding;
|
public readonly int Binding;
|
||||||
public readonly byte Slot;
|
public readonly byte Slot;
|
||||||
public readonly byte SbCbSlot;
|
public readonly byte SbCbSlot;
|
||||||
public readonly ushort SbCbOffset;
|
public readonly ushort SbCbOffset;
|
||||||
public readonly BufferUsageFlags Flags;
|
public readonly BufferUsageFlags Flags;
|
||||||
|
|
||||||
public BufferDescriptor(int binding, int slot)
|
public BufferDescriptor(int set, int binding, int slot)
|
||||||
{
|
{
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
Slot = (byte)slot;
|
Slot = (byte)slot;
|
||||||
SbCbSlot = 0;
|
SbCbSlot = 0;
|
||||||
@ -19,8 +21,9 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
Flags = BufferUsageFlags.None;
|
Flags = BufferUsageFlags.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferDescriptor(int binding, int slot, int sbCbSlot, int sbCbOffset, BufferUsageFlags flags)
|
public BufferDescriptor(int set, int binding, int slot, int sbCbSlot, int sbCbOffset, BufferUsageFlags flags)
|
||||||
{
|
{
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
Slot = (byte)slot;
|
Slot = (byte)slot;
|
||||||
SbCbSlot = (byte)sbCbSlot;
|
SbCbSlot = (byte)sbCbSlot;
|
||||||
|
@ -462,7 +462,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
context.Properties.Textures.TryGetValue(texOp.Binding, out TextureDefinition definition);
|
context.Properties.Textures.TryGetValue(texOp.GetTextureSetAndBinding(), out TextureDefinition definition);
|
||||||
bool hasLod = !definition.Type.HasFlag(SamplerType.Multisample) && (definition.Type & SamplerType.Mask) != SamplerType.TextureBuffer;
|
bool hasLod = !definition.Type.HasFlag(SamplerType.Multisample) && (definition.Type & SamplerType.Mask) != SamplerType.TextureBuffer;
|
||||||
string texCall;
|
string texCall;
|
||||||
|
|
||||||
@ -639,7 +639,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||||||
|
|
||||||
private static string GetSamplerName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
private static string GetSamplerName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
||||||
{
|
{
|
||||||
TextureDefinition textureDefinition = context.Properties.Textures[texOp.Binding];
|
TextureDefinition textureDefinition = context.Properties.Textures[texOp.GetTextureSetAndBinding()];
|
||||||
string name = textureDefinition.Name;
|
string name = textureDefinition.Name;
|
||||||
|
|
||||||
if (textureDefinition.ArrayLength != 1)
|
if (textureDefinition.ArrayLength != 1)
|
||||||
@ -649,7 +649,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||||||
|
|
||||||
if (texOp.IsSeparate)
|
if (texOp.IsSeparate)
|
||||||
{
|
{
|
||||||
TextureDefinition samplerDefinition = context.Properties.Textures[texOp.SamplerBinding];
|
TextureDefinition samplerDefinition = context.Properties.Textures[texOp.GetSamplerSetAndBinding()];
|
||||||
string samplerName = samplerDefinition.Name;
|
string samplerName = samplerDefinition.Name;
|
||||||
|
|
||||||
if (samplerDefinition.ArrayLength != 1)
|
if (samplerDefinition.ArrayLength != 1)
|
||||||
@ -665,7 +665,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||||||
|
|
||||||
private static string GetImageName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
private static string GetImageName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
||||||
{
|
{
|
||||||
TextureDefinition definition = context.Properties.Images[texOp.Binding];
|
TextureDefinition definition = context.Properties.Images[texOp.GetTextureSetAndBinding()];
|
||||||
string name = definition.Name;
|
string name = definition.Name;
|
||||||
|
|
||||||
if (definition.ArrayLength != 1)
|
if (definition.ArrayLength != 1)
|
||||||
|
@ -33,9 +33,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
public Dictionary<int, Instruction> LocalMemories { get; } = new();
|
public Dictionary<int, Instruction> LocalMemories { get; } = new();
|
||||||
public Dictionary<int, Instruction> SharedMemories { get; } = new();
|
public Dictionary<int, Instruction> SharedMemories { get; } = new();
|
||||||
|
|
||||||
public Dictionary<int, SamplerType> SamplersTypes { get; } = new();
|
public Dictionary<SetBindingPair, SamplerType> SamplersTypes { get; } = new();
|
||||||
public Dictionary<int, SamplerDeclaration> Samplers { get; } = new();
|
public Dictionary<SetBindingPair, SamplerDeclaration> Samplers { get; } = new();
|
||||||
public Dictionary<int, ImageDeclaration> Images { get; } = new();
|
public Dictionary<SetBindingPair, ImageDeclaration> Images { get; } = new();
|
||||||
|
|
||||||
public Dictionary<IoDefinition, Instruction> Inputs { get; } = new();
|
public Dictionary<IoDefinition, Instruction> Inputs { get; } = new();
|
||||||
public Dictionary<IoDefinition, Instruction> Outputs { get; } = new();
|
public Dictionary<IoDefinition, Instruction> Outputs { get; } = new();
|
||||||
@ -98,11 +98,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
Logger = parameters.Logger;
|
Logger = parameters.Logger;
|
||||||
TargetApi = parameters.TargetApi;
|
TargetApi = parameters.TargetApi;
|
||||||
|
|
||||||
AddCapability(Capability.Shader);
|
|
||||||
AddCapability(Capability.Float64);
|
|
||||||
|
|
||||||
SetMemoryModel(AddressingModel.Logical, MemoryModel.GLSL450);
|
|
||||||
|
|
||||||
Delegates = new SpirvDelegates(this);
|
Delegates = new SpirvDelegates(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,13 +208,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
var sampledImageVariable = context.Variable(sampledImageArrayPointerType, StorageClass.UniformConstant);
|
var sampledImageVariable = context.Variable(sampledImageArrayPointerType, StorageClass.UniformConstant);
|
||||||
|
|
||||||
context.Samplers.Add(sampler.Binding, new SamplerDeclaration(
|
context.Samplers.Add(new(sampler.Set, sampler.Binding), new SamplerDeclaration(
|
||||||
imageType,
|
imageType,
|
||||||
sampledImageType,
|
sampledImageType,
|
||||||
sampledImagePointerType,
|
sampledImagePointerType,
|
||||||
sampledImageVariable,
|
sampledImageVariable,
|
||||||
sampler.ArrayLength != 1));
|
sampler.ArrayLength != 1));
|
||||||
context.SamplersTypes.Add(sampler.Binding, sampler.Type);
|
context.SamplersTypes.Add(new(sampler.Set, sampler.Binding), sampler.Type);
|
||||||
|
|
||||||
context.Name(sampledImageVariable, sampler.Name);
|
context.Name(sampledImageVariable, sampler.Name);
|
||||||
context.Decorate(sampledImageVariable, Decoration.DescriptorSet, (LiteralInteger)setIndex);
|
context.Decorate(sampledImageVariable, Decoration.DescriptorSet, (LiteralInteger)setIndex);
|
||||||
@ -256,7 +256,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
var imageVariable = context.Variable(imageArrayPointerType, StorageClass.UniformConstant);
|
var imageVariable = context.Variable(imageArrayPointerType, StorageClass.UniformConstant);
|
||||||
|
|
||||||
context.Images.Add(image.Binding, new ImageDeclaration(imageType, imagePointerType, imageVariable, image.ArrayLength != 1));
|
context.Images.Add(new(image.Set, image.Binding), new ImageDeclaration(imageType, imagePointerType, imageVariable, image.ArrayLength != 1));
|
||||||
|
|
||||||
context.Name(imageVariable, image.Name);
|
context.Name(imageVariable, image.Name);
|
||||||
context.Decorate(imageVariable, Decoration.DescriptorSet, (LiteralInteger)setIndex);
|
context.Decorate(imageVariable, Decoration.DescriptorSet, (LiteralInteger)setIndex);
|
||||||
|
@ -602,7 +602,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
return context.Get(type, texOp.GetSource(srcIndex++));
|
return context.Get(type, texOp.GetSource(srcIndex++));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageDeclaration declaration = context.Images[texOp.Binding];
|
ImageDeclaration declaration = context.Images[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = declaration.Image;
|
SpvInstruction image = declaration.Image;
|
||||||
|
|
||||||
SpvInstruction resultType = context.GetType(componentType);
|
SpvInstruction resultType = context.GetType(componentType);
|
||||||
@ -681,7 +681,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
return context.Get(type, texOp.GetSource(srcIndex++));
|
return context.Get(type, texOp.GetSource(srcIndex++));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageDeclaration declaration = context.Images[texOp.Binding];
|
ImageDeclaration declaration = context.Images[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = declaration.Image;
|
SpvInstruction image = declaration.Image;
|
||||||
|
|
||||||
if (declaration.IsIndexed)
|
if (declaration.IsIndexed)
|
||||||
@ -738,7 +738,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
return context.Get(type, texOp.GetSource(srcIndex++));
|
return context.Get(type, texOp.GetSource(srcIndex++));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageDeclaration declaration = context.Images[texOp.Binding];
|
ImageDeclaration declaration = context.Images[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = declaration.Image;
|
SpvInstruction image = declaration.Image;
|
||||||
|
|
||||||
if (declaration.IsIndexed)
|
if (declaration.IsIndexed)
|
||||||
@ -837,7 +837,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
return context.Get(type, texOp.GetSource(srcIndex++));
|
return context.Get(type, texOp.GetSource(srcIndex++));
|
||||||
}
|
}
|
||||||
|
|
||||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||||
|
|
||||||
int pCount = texOp.Type.GetDimensions();
|
int pCount = texOp.Type.GetDimensions();
|
||||||
@ -1161,7 +1161,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
return context.Get(type, texOp.GetSource(srcIndex++));
|
return context.Get(type, texOp.GetSource(srcIndex++));
|
||||||
}
|
}
|
||||||
|
|
||||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||||
|
|
||||||
int coordsCount = texOp.Type.GetDimensions();
|
int coordsCount = texOp.Type.GetDimensions();
|
||||||
@ -1433,7 +1433,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
int srcIndex = 0;
|
int srcIndex = 0;
|
||||||
|
|
||||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||||
|
|
||||||
image = context.Image(declaration.ImageType, image);
|
image = context.Image(declaration.ImageType, image);
|
||||||
@ -1449,7 +1449,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
int srcIndex = 0;
|
int srcIndex = 0;
|
||||||
|
|
||||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()];
|
||||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||||
|
|
||||||
image = context.Image(declaration.ImageType, image);
|
image = context.Image(declaration.ImageType, image);
|
||||||
@ -1460,7 +1460,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var type = context.SamplersTypes[texOp.Binding];
|
var type = context.SamplersTypes[texOp.GetTextureSetAndBinding()];
|
||||||
bool hasLod = !type.HasFlag(SamplerType.Multisample) && type != SamplerType.TextureBuffer;
|
bool hasLod = !type.HasFlag(SamplerType.Multisample) && type != SamplerType.TextureBuffer;
|
||||||
|
|
||||||
int dimensions = (type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : type.GetDimensions();
|
int dimensions = (type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : type.GetDimensions();
|
||||||
@ -1889,7 +1889,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
{
|
{
|
||||||
image = context.Load(declaration.ImageType, image);
|
image = context.Load(declaration.ImageType, image);
|
||||||
|
|
||||||
SamplerDeclaration samplerDeclaration = context.Samplers[texOp.SamplerBinding];
|
SamplerDeclaration samplerDeclaration = context.Samplers[texOp.GetSamplerSetAndBinding()];
|
||||||
|
|
||||||
SpvInstruction sampler = samplerDeclaration.Image;
|
SpvInstruction sampler = samplerDeclaration.Image;
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
CodeGenContext context = new(info, parameters, instPool, integerPool);
|
CodeGenContext context = new(info, parameters, instPool, integerPool);
|
||||||
|
|
||||||
|
context.AddCapability(Capability.Shader);
|
||||||
|
|
||||||
|
context.SetMemoryModel(AddressingModel.Logical, MemoryModel.GLSL450);
|
||||||
|
|
||||||
context.AddCapability(Capability.GroupNonUniformBallot);
|
context.AddCapability(Capability.GroupNonUniformBallot);
|
||||||
context.AddCapability(Capability.GroupNonUniformShuffle);
|
context.AddCapability(Capability.GroupNonUniformShuffle);
|
||||||
context.AddCapability(Capability.GroupNonUniformVote);
|
context.AddCapability(Capability.GroupNonUniformVote);
|
||||||
@ -51,6 +55,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
context.AddCapability(Capability.ImageQuery);
|
context.AddCapability(Capability.ImageQuery);
|
||||||
context.AddCapability(Capability.SampledBuffer);
|
context.AddCapability(Capability.SampledBuffer);
|
||||||
|
|
||||||
|
if (parameters.HostCapabilities.SupportsShaderFloat64)
|
||||||
|
{
|
||||||
|
context.AddCapability(Capability.Float64);
|
||||||
|
}
|
||||||
|
|
||||||
if (parameters.Definitions.TransformFeedbackEnabled && parameters.Definitions.LastInVertexPipeline)
|
if (parameters.Definitions.TransformFeedbackEnabled && parameters.Definitions.LastInVertexPipeline)
|
||||||
{
|
{
|
||||||
context.AddCapability(Capability.TransformFeedback);
|
context.AddCapability(Capability.TransformFeedback);
|
||||||
@ -58,7 +67,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||||||
|
|
||||||
if (parameters.Definitions.Stage == ShaderStage.Fragment)
|
if (parameters.Definitions.Stage == ShaderStage.Fragment)
|
||||||
{
|
{
|
||||||
if (context.Info.IoDefinitions.Contains(new IoDefinition(StorageKind.Input, IoVariable.Layer)))
|
if (context.Info.IoDefinitions.Contains(new IoDefinition(StorageKind.Input, IoVariable.Layer)) ||
|
||||||
|
context.Info.IoDefinitions.Contains(new IoDefinition(StorageKind.Input, IoVariable.PrimitiveId)))
|
||||||
{
|
{
|
||||||
context.AddCapability(Capability.Geometry);
|
context.AddCapability(Capability.Geometry);
|
||||||
}
|
}
|
||||||
|
@ -27,34 +27,43 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
|
ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries the binding number of a constant buffer.
|
/// Gets the binding number of a constant buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">Constant buffer index</param>
|
/// <param name="index">Constant buffer index</param>
|
||||||
/// <returns>Binding number</returns>
|
/// <returns>Binding number</returns>
|
||||||
int CreateConstantBufferBinding(int index);
|
SetBindingPair CreateConstantBufferBinding(int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries the binding number of an image.
|
/// Gets the binding number of an image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count">For array of images, the number of elements of the array, otherwise it should be 1</param>
|
/// <param name="count">For array of images, the number of elements of the array, otherwise it should be 1</param>
|
||||||
/// <param name="isBuffer">Indicates if the image is a buffer image</param>
|
/// <param name="isBuffer">Indicates if the image is a buffer image</param>
|
||||||
/// <returns>Binding number</returns>
|
/// <returns>Binding number</returns>
|
||||||
int CreateImageBinding(int count, bool isBuffer);
|
SetBindingPair CreateImageBinding(int count, bool isBuffer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries the binding number of a storage buffer.
|
/// Gets the binding number of a storage buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">Storage buffer index</param>
|
/// <param name="index">Storage buffer index</param>
|
||||||
/// <returns>Binding number</returns>
|
/// <returns>Binding number</returns>
|
||||||
int CreateStorageBufferBinding(int index);
|
SetBindingPair CreateStorageBufferBinding(int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries the binding number of a texture.
|
/// Gets the binding number of a texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count">For array of textures, the number of elements of the array, otherwise it should be 1</param>
|
/// <param name="count">For array of textures, the number of elements of the array, otherwise it should be 1</param>
|
||||||
/// <param name="isBuffer">Indicates if the texture is a buffer texture</param>
|
/// <param name="isBuffer">Indicates if the texture is a buffer texture</param>
|
||||||
/// <returns>Binding number</returns>
|
/// <returns>Binding number</returns>
|
||||||
int CreateTextureBinding(int count, bool isBuffer);
|
SetBindingPair CreateTextureBinding(int count, bool isBuffer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the set index for an additional set, or -1 if there's no extra set available.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Extra set index, or -1 if not available</returns>
|
||||||
|
int CreateExtraSet()
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries Local Size X for compute shaders.
|
/// Queries Local Size X for compute shaders.
|
||||||
|
@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
|
|
||||||
if (op.BVal)
|
if (op.BVal)
|
||||||
{
|
{
|
||||||
context.Copy(dest, context.ConditionalSelect(res, ConstF(1), Const(0)));
|
context.Copy(dest, context.ConditionalSelect(res, ConstF(1), ConstF(0)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -278,7 +278,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
flags |= TextureFlags.Bindless;
|
flags |= TextureFlags.Bindless;
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.ImageAtomic,
|
Instruction.ImageAtomic,
|
||||||
type,
|
type,
|
||||||
format,
|
format,
|
||||||
@ -286,7 +286,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
imm);
|
imm);
|
||||||
|
|
||||||
Operand res = context.ImageAtomic(type, format, flags, binding, sources);
|
Operand res = context.ImageAtomic(type, format, flags, setAndBinding, sources);
|
||||||
|
|
||||||
context.Copy(d, res);
|
context.Copy(d, res);
|
||||||
}
|
}
|
||||||
@ -389,7 +389,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
|
|
||||||
TextureFormat format = isBindless ? TextureFormat.Unknown : ShaderProperties.GetTextureFormat(context.TranslatorContext.GpuAccessor, handle);
|
TextureFormat format = isBindless ? TextureFormat.Unknown : ShaderProperties.GetTextureFormat(context.TranslatorContext.GpuAccessor, handle);
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.ImageLoad,
|
Instruction.ImageLoad,
|
||||||
type,
|
type,
|
||||||
format,
|
format,
|
||||||
@ -397,7 +397,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
handle);
|
handle);
|
||||||
|
|
||||||
context.ImageLoad(type, format, flags, binding, (int)componentMask, dests, sources);
|
context.ImageLoad(type, format, flags, setAndBinding, (int)componentMask, dests, sources);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
|
|
||||||
TextureFormat format = GetTextureFormat(size);
|
TextureFormat format = GetTextureFormat(size);
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.ImageLoad,
|
Instruction.ImageLoad,
|
||||||
type,
|
type,
|
||||||
format,
|
format,
|
||||||
@ -440,7 +440,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
handle);
|
handle);
|
||||||
|
|
||||||
context.ImageLoad(type, format, flags, binding, compMask, dests, sources);
|
context.ImageLoad(type, format, flags, setAndBinding, compMask, dests, sources);
|
||||||
|
|
||||||
switch (size)
|
switch (size)
|
||||||
{
|
{
|
||||||
@ -552,7 +552,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
flags |= TextureFlags.Bindless;
|
flags |= TextureFlags.Bindless;
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.ImageAtomic,
|
Instruction.ImageAtomic,
|
||||||
type,
|
type,
|
||||||
format,
|
format,
|
||||||
@ -560,7 +560,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
imm);
|
imm);
|
||||||
|
|
||||||
context.ImageAtomic(type, format, flags, binding, sources);
|
context.ImageAtomic(type, format, flags, setAndBinding, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EmitSust(
|
private static void EmitSust(
|
||||||
@ -679,7 +679,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
flags |= TextureFlags.Coherent;
|
flags |= TextureFlags.Coherent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.ImageStore,
|
Instruction.ImageStore,
|
||||||
type,
|
type,
|
||||||
format,
|
format,
|
||||||
@ -687,7 +687,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
handle);
|
handle);
|
||||||
|
|
||||||
context.ImageStore(type, format, flags, binding, sources);
|
context.ImageStore(type, format, flags, setAndBinding, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetComponentSizeInBytesLog2(SuatomSize size)
|
private static int GetComponentSizeInBytesLog2(SuatomSize size)
|
||||||
|
@ -885,7 +885,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
return Register(dest++, RegisterType.Gpr);
|
return Register(dest++, RegisterType.Gpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.Lod,
|
Instruction.Lod,
|
||||||
type,
|
type,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
@ -913,7 +913,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The instruction component order is the inverse of GLSL's.
|
// The instruction component order is the inverse of GLSL's.
|
||||||
Operand res = context.Lod(type, flags, binding, compIndex ^ 1, sources);
|
Operand res = context.Lod(type, flags, setAndBinding, compIndex ^ 1, sources);
|
||||||
|
|
||||||
res = context.FPMultiply(res, ConstF(256.0f));
|
res = context.FPMultiply(res, ConstF(256.0f));
|
||||||
|
|
||||||
@ -1116,12 +1116,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;
|
TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;
|
||||||
int binding;
|
SetBindingPair setAndBinding;
|
||||||
|
|
||||||
switch (query)
|
switch (query)
|
||||||
{
|
{
|
||||||
case TexQuery.TexHeaderDimension:
|
case TexQuery.TexHeaderDimension:
|
||||||
binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.TextureQuerySize,
|
Instruction.TextureQuerySize,
|
||||||
type,
|
type,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
@ -1140,13 +1140,13 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Copy(d, context.TextureQuerySize(type, flags, binding, compIndex, sources));
|
context.Copy(d, context.TextureQuerySize(type, flags, setAndBinding, compIndex, sources));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TexQuery.TexHeaderTextureType:
|
case TexQuery.TexHeaderTextureType:
|
||||||
binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.TextureQuerySamples,
|
Instruction.TextureQuerySamples,
|
||||||
type,
|
type,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
@ -1171,7 +1171,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
|
|
||||||
if (d != null)
|
if (d != null)
|
||||||
{
|
{
|
||||||
context.Copy(d, context.TextureQuerySamples(type, flags, binding, sources));
|
context.Copy(d, context.TextureQuerySamples(type, flags, setAndBinding, sources));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1191,7 +1191,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
Operand[] dests,
|
Operand[] dests,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
int binding = flags.HasFlag(TextureFlags.Bindless) ? 0 : context.ResourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = flags.HasFlag(TextureFlags.Bindless) ? default : context.ResourceManager.GetTextureOrImageBinding(
|
||||||
Instruction.TextureSample,
|
Instruction.TextureSample,
|
||||||
type,
|
type,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
@ -1199,7 +1199,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||||||
TextureOperation.DefaultCbufSlot,
|
TextureOperation.DefaultCbufSlot,
|
||||||
handle);
|
handle);
|
||||||
|
|
||||||
context.TextureSample(type, flags, binding, componentMask, dests, sources);
|
context.TextureSample(type, flags, setAndBinding, componentMask, dests, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SamplerType ConvertSamplerType(TexDim dimensions)
|
private static SamplerType ConvertSamplerType(TexDim dimensions)
|
||||||
|
@ -156,6 +156,26 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsComparison(this Instruction inst)
|
||||||
|
{
|
||||||
|
switch (inst & Instruction.Mask)
|
||||||
|
{
|
||||||
|
case Instruction.CompareEqual:
|
||||||
|
case Instruction.CompareGreater:
|
||||||
|
case Instruction.CompareGreaterOrEqual:
|
||||||
|
case Instruction.CompareGreaterOrEqualU32:
|
||||||
|
case Instruction.CompareGreaterU32:
|
||||||
|
case Instruction.CompareLess:
|
||||||
|
case Instruction.CompareLessOrEqual:
|
||||||
|
case Instruction.CompareLessOrEqualU32:
|
||||||
|
case Instruction.CompareLessU32:
|
||||||
|
case Instruction.CompareNotEqual:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsTextureQuery(this Instruction inst)
|
public static bool IsTextureQuery(this Instruction inst)
|
||||||
{
|
{
|
||||||
inst &= Instruction.Mask;
|
inst &= Instruction.Mask;
|
||||||
|
@ -8,7 +8,9 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
|||||||
public TextureFormat Format { get; set; }
|
public TextureFormat Format { get; set; }
|
||||||
public TextureFlags Flags { get; private set; }
|
public TextureFlags Flags { get; private set; }
|
||||||
|
|
||||||
|
public int Set { get; private set; }
|
||||||
public int Binding { get; private set; }
|
public int Binding { get; private set; }
|
||||||
|
public int SamplerSet { get; private set; }
|
||||||
public int SamplerBinding { get; private set; }
|
public int SamplerBinding { get; private set; }
|
||||||
|
|
||||||
public TextureOperation(
|
public TextureOperation(
|
||||||
@ -16,6 +18,7 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
|||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
|
int set,
|
||||||
int binding,
|
int binding,
|
||||||
int compIndex,
|
int compIndex,
|
||||||
Operand[] dests,
|
Operand[] dests,
|
||||||
@ -24,24 +27,28 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
|||||||
Type = type;
|
Type = type;
|
||||||
Format = format;
|
Format = format;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
|
SamplerSet = -1;
|
||||||
SamplerBinding = -1;
|
SamplerBinding = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TurnIntoArray(int binding)
|
public void TurnIntoArray(SetBindingPair setAndBinding)
|
||||||
{
|
{
|
||||||
Flags &= ~TextureFlags.Bindless;
|
Flags &= ~TextureFlags.Bindless;
|
||||||
Binding = binding;
|
Set = setAndBinding.SetIndex;
|
||||||
|
Binding = setAndBinding.Binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TurnIntoArray(int textureBinding, int samplerBinding)
|
public void TurnIntoArray(SetBindingPair textureSetAndBinding, SetBindingPair samplerSetAndBinding)
|
||||||
{
|
{
|
||||||
TurnIntoArray(textureBinding);
|
TurnIntoArray(textureSetAndBinding);
|
||||||
|
|
||||||
SamplerBinding = samplerBinding;
|
SamplerSet = samplerSetAndBinding.SetIndex;
|
||||||
|
SamplerBinding = samplerSetAndBinding.Binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBinding(int binding)
|
public void SetBinding(SetBindingPair setAndBinding)
|
||||||
{
|
{
|
||||||
if ((Flags & TextureFlags.Bindless) != 0)
|
if ((Flags & TextureFlags.Bindless) != 0)
|
||||||
{
|
{
|
||||||
@ -50,7 +57,8 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
|||||||
RemoveSource(0);
|
RemoveSource(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Binding = binding;
|
Set = setAndBinding.SetIndex;
|
||||||
|
Binding = setAndBinding.Binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetLodLevelFlag()
|
public void SetLodLevelFlag()
|
||||||
|
4
src/Ryujinx.Graphics.Shader/SetBindingPair.cs
Normal file
4
src/Ryujinx.Graphics.Shader/SetBindingPair.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Ryujinx.Graphics.Shader
|
||||||
|
{
|
||||||
|
public readonly record struct SetBindingPair(int SetIndex, int Binding);
|
||||||
|
}
|
@ -8,7 +8,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
public TextureFormat Format { get; }
|
public TextureFormat Format { get; }
|
||||||
public TextureFlags Flags { get; }
|
public TextureFlags Flags { get; }
|
||||||
|
|
||||||
|
public int Set { get; }
|
||||||
public int Binding { get; }
|
public int Binding { get; }
|
||||||
|
public int SamplerSet { get; }
|
||||||
public int SamplerBinding { get; }
|
public int SamplerBinding { get; }
|
||||||
|
|
||||||
public bool IsSeparate => SamplerBinding >= 0;
|
public bool IsSeparate => SamplerBinding >= 0;
|
||||||
@ -18,7 +20,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
|
int set,
|
||||||
int binding,
|
int binding,
|
||||||
|
int samplerSet,
|
||||||
int samplerBinding,
|
int samplerBinding,
|
||||||
int index,
|
int index,
|
||||||
params IAstNode[] sources) : base(inst, StorageKind.None, false, index, sources, sources.Length)
|
params IAstNode[] sources) : base(inst, StorageKind.None, false, index, sources, sources.Length)
|
||||||
@ -26,8 +30,20 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
Type = type;
|
Type = type;
|
||||||
Format = format;
|
Format = format;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
|
SamplerSet = samplerSet;
|
||||||
SamplerBinding = samplerBinding;
|
SamplerBinding = samplerBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SetBindingPair GetTextureSetAndBinding()
|
||||||
|
{
|
||||||
|
return new SetBindingPair(Set, Binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetBindingPair GetSamplerSetAndBinding()
|
||||||
|
{
|
||||||
|
return new SetBindingPair(SamplerSet, SamplerBinding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<int, BufferDefinition> _constantBuffers;
|
private readonly Dictionary<int, BufferDefinition> _constantBuffers;
|
||||||
private readonly Dictionary<int, BufferDefinition> _storageBuffers;
|
private readonly Dictionary<int, BufferDefinition> _storageBuffers;
|
||||||
private readonly Dictionary<int, TextureDefinition> _textures;
|
private readonly Dictionary<SetBindingPair, TextureDefinition> _textures;
|
||||||
private readonly Dictionary<int, TextureDefinition> _images;
|
private readonly Dictionary<SetBindingPair, TextureDefinition> _images;
|
||||||
private readonly Dictionary<int, MemoryDefinition> _localMemories;
|
private readonly Dictionary<int, MemoryDefinition> _localMemories;
|
||||||
private readonly Dictionary<int, MemoryDefinition> _sharedMemories;
|
private readonly Dictionary<int, MemoryDefinition> _sharedMemories;
|
||||||
|
|
||||||
public IReadOnlyDictionary<int, BufferDefinition> ConstantBuffers => _constantBuffers;
|
public IReadOnlyDictionary<int, BufferDefinition> ConstantBuffers => _constantBuffers;
|
||||||
public IReadOnlyDictionary<int, BufferDefinition> StorageBuffers => _storageBuffers;
|
public IReadOnlyDictionary<int, BufferDefinition> StorageBuffers => _storageBuffers;
|
||||||
public IReadOnlyDictionary<int, TextureDefinition> Textures => _textures;
|
public IReadOnlyDictionary<SetBindingPair, TextureDefinition> Textures => _textures;
|
||||||
public IReadOnlyDictionary<int, TextureDefinition> Images => _images;
|
public IReadOnlyDictionary<SetBindingPair, TextureDefinition> Images => _images;
|
||||||
public IReadOnlyDictionary<int, MemoryDefinition> LocalMemories => _localMemories;
|
public IReadOnlyDictionary<int, MemoryDefinition> LocalMemories => _localMemories;
|
||||||
public IReadOnlyDictionary<int, MemoryDefinition> SharedMemories => _sharedMemories;
|
public IReadOnlyDictionary<int, MemoryDefinition> SharedMemories => _sharedMemories;
|
||||||
|
|
||||||
@ -22,8 +22,8 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
{
|
{
|
||||||
_constantBuffers = new Dictionary<int, BufferDefinition>();
|
_constantBuffers = new Dictionary<int, BufferDefinition>();
|
||||||
_storageBuffers = new Dictionary<int, BufferDefinition>();
|
_storageBuffers = new Dictionary<int, BufferDefinition>();
|
||||||
_textures = new Dictionary<int, TextureDefinition>();
|
_textures = new Dictionary<SetBindingPair, TextureDefinition>();
|
||||||
_images = new Dictionary<int, TextureDefinition>();
|
_images = new Dictionary<SetBindingPair, TextureDefinition>();
|
||||||
_localMemories = new Dictionary<int, MemoryDefinition>();
|
_localMemories = new Dictionary<int, MemoryDefinition>();
|
||||||
_sharedMemories = new Dictionary<int, MemoryDefinition>();
|
_sharedMemories = new Dictionary<int, MemoryDefinition>();
|
||||||
}
|
}
|
||||||
@ -40,12 +40,12 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
|
|
||||||
public void AddOrUpdateTexture(TextureDefinition definition)
|
public void AddOrUpdateTexture(TextureDefinition definition)
|
||||||
{
|
{
|
||||||
_textures[definition.Binding] = definition;
|
_textures[new(definition.Set, definition.Binding)] = definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddOrUpdateImage(TextureDefinition definition)
|
public void AddOrUpdateImage(TextureDefinition definition)
|
||||||
{
|
{
|
||||||
_images[definition.Binding] = definition;
|
_images[new(definition.Set, definition.Binding)] = definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AddLocalMemory(MemoryDefinition definition)
|
public int AddLocalMemory(MemoryDefinition definition)
|
||||||
|
@ -169,7 +169,17 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||||||
|
|
||||||
AstTextureOperation GetAstTextureOperation(TextureOperation texOp)
|
AstTextureOperation GetAstTextureOperation(TextureOperation texOp)
|
||||||
{
|
{
|
||||||
return new AstTextureOperation(inst, texOp.Type, texOp.Format, texOp.Flags, texOp.Binding, texOp.SamplerBinding, texOp.Index, sources);
|
return new AstTextureOperation(
|
||||||
|
inst,
|
||||||
|
texOp.Type,
|
||||||
|
texOp.Format,
|
||||||
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
|
texOp.Binding,
|
||||||
|
texOp.SamplerSet,
|
||||||
|
texOp.SamplerBinding,
|
||||||
|
texOp.Index,
|
||||||
|
sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
int componentsCount = BitOperations.PopCount((uint)operation.Index);
|
int componentsCount = BitOperations.PopCount((uint)operation.Index);
|
||||||
|
@ -4,6 +4,7 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
{
|
{
|
||||||
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
|
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
|
||||||
|
|
||||||
|
public readonly int Set;
|
||||||
public readonly int Binding;
|
public readonly int Binding;
|
||||||
|
|
||||||
public readonly SamplerType Type;
|
public readonly SamplerType Type;
|
||||||
@ -18,6 +19,7 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
public readonly TextureUsageFlags Flags;
|
public readonly TextureUsageFlags Flags;
|
||||||
|
|
||||||
public TextureDescriptor(
|
public TextureDescriptor(
|
||||||
|
int set,
|
||||||
int binding,
|
int binding,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
@ -27,6 +29,7 @@ namespace Ryujinx.Graphics.Shader
|
|||||||
bool separate,
|
bool separate,
|
||||||
TextureUsageFlags flags)
|
TextureUsageFlags flags)
|
||||||
{
|
{
|
||||||
|
Set = set;
|
||||||
Binding = binding;
|
Binding = binding;
|
||||||
Type = type;
|
Type = type;
|
||||||
Format = format;
|
Format = format;
|
||||||
|
@ -124,7 +124,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
this.TextureSample(
|
this.TextureSample(
|
||||||
SamplerType.TextureBuffer,
|
SamplerType.TextureBuffer,
|
||||||
TextureFlags.IntCoords,
|
TextureFlags.IntCoords,
|
||||||
ResourceManager.Reservations.IndexBufferTextureBinding,
|
ResourceManager.Reservations.GetIndexBufferTextureSetAndBinding(),
|
||||||
1,
|
1,
|
||||||
new[] { vertexIndexVr },
|
new[] { vertexIndexVr },
|
||||||
new[] { this.IAdd(ibBaseOffset, outputVertexOffset) });
|
new[] { this.IAdd(ibBaseOffset, outputVertexOffset) });
|
||||||
@ -145,7 +145,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
this.TextureSample(
|
this.TextureSample(
|
||||||
SamplerType.TextureBuffer,
|
SamplerType.TextureBuffer,
|
||||||
TextureFlags.IntCoords,
|
TextureFlags.IntCoords,
|
||||||
ResourceManager.Reservations.TopologyRemapBufferTextureBinding,
|
ResourceManager.Reservations.GetTopologyRemapBufferTextureSetAndBinding(),
|
||||||
1,
|
1,
|
||||||
new[] { vertexIndex },
|
new[] { vertexIndex },
|
||||||
new[] { this.IAdd(baseVertex, Const(index)) });
|
new[] { this.IAdd(baseVertex, Const(index)) });
|
||||||
|
@ -618,12 +618,21 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
Operand dest = Local();
|
Operand dest = Local();
|
||||||
|
|
||||||
context.Add(new TextureOperation(Instruction.ImageAtomic, type, format, flags, binding, 0, new[] { dest }, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.ImageAtomic,
|
||||||
|
type,
|
||||||
|
format,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
0,
|
||||||
|
new[] { dest },
|
||||||
|
sources));
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -633,12 +642,21 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
int compMask,
|
int compMask,
|
||||||
Operand[] dests,
|
Operand[] dests,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
context.Add(new TextureOperation(Instruction.ImageLoad, type, format, flags, binding, compMask, dests, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.ImageLoad,
|
||||||
|
type,
|
||||||
|
format,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
compMask,
|
||||||
|
dests,
|
||||||
|
sources));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ImageStore(
|
public static void ImageStore(
|
||||||
@ -646,10 +664,19 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
context.Add(new TextureOperation(Instruction.ImageStore, type, format, flags, binding, 0, null, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.ImageStore,
|
||||||
|
type,
|
||||||
|
format,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
sources));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
|
public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
|
||||||
@ -718,13 +745,22 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
this EmitterContext context,
|
this EmitterContext context,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
int compIndex,
|
int compIndex,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
Operand dest = Local();
|
Operand dest = Local();
|
||||||
|
|
||||||
context.Add(new TextureOperation(Instruction.Lod, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.Lod,
|
||||||
|
type,
|
||||||
|
TextureFormat.Unknown,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
compIndex,
|
||||||
|
new[] { dest },
|
||||||
|
sources));
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -889,24 +925,42 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
this EmitterContext context,
|
this EmitterContext context,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
int compMask,
|
int compMask,
|
||||||
Operand[] dests,
|
Operand[] dests,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
context.Add(new TextureOperation(Instruction.TextureSample, type, TextureFormat.Unknown, flags, binding, compMask, dests, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.TextureSample,
|
||||||
|
type,
|
||||||
|
TextureFormat.Unknown,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
compMask,
|
||||||
|
dests,
|
||||||
|
sources));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operand TextureQuerySamples(
|
public static Operand TextureQuerySamples(
|
||||||
this EmitterContext context,
|
this EmitterContext context,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
Operand dest = Local();
|
Operand dest = Local();
|
||||||
|
|
||||||
context.Add(new TextureOperation(Instruction.TextureQuerySamples, type, TextureFormat.Unknown, flags, binding, 0, new[] { dest }, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.TextureQuerySamples,
|
||||||
|
type,
|
||||||
|
TextureFormat.Unknown,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
0,
|
||||||
|
new[] { dest },
|
||||||
|
sources));
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -915,13 +969,22 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
this EmitterContext context,
|
this EmitterContext context,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFlags flags,
|
TextureFlags flags,
|
||||||
int binding,
|
SetBindingPair setAndBinding,
|
||||||
int compIndex,
|
int compIndex,
|
||||||
Operand[] sources)
|
Operand[] sources)
|
||||||
{
|
{
|
||||||
Operand dest = Local();
|
Operand dest = Local();
|
||||||
|
|
||||||
context.Add(new TextureOperation(Instruction.TextureQuerySize, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources));
|
context.Add(new TextureOperation(
|
||||||
|
Instruction.TextureQuerySize,
|
||||||
|
type,
|
||||||
|
TextureFormat.Unknown,
|
||||||
|
flags,
|
||||||
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
|
compIndex,
|
||||||
|
new[] { dest },
|
||||||
|
sources));
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
public readonly bool SupportsGeometryShaderPassthrough;
|
public readonly bool SupportsGeometryShaderPassthrough;
|
||||||
public readonly bool SupportsShaderBallot;
|
public readonly bool SupportsShaderBallot;
|
||||||
public readonly bool SupportsShaderBarrierDivergence;
|
public readonly bool SupportsShaderBarrierDivergence;
|
||||||
|
public readonly bool SupportsShaderFloat64;
|
||||||
public readonly bool SupportsTextureShadowLod;
|
public readonly bool SupportsTextureShadowLod;
|
||||||
public readonly bool SupportsViewportMask;
|
public readonly bool SupportsViewportMask;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
bool supportsGeometryShaderPassthrough,
|
bool supportsGeometryShaderPassthrough,
|
||||||
bool supportsShaderBallot,
|
bool supportsShaderBallot,
|
||||||
bool supportsShaderBarrierDivergence,
|
bool supportsShaderBarrierDivergence,
|
||||||
|
bool supportsShaderFloat64,
|
||||||
bool supportsTextureShadowLod,
|
bool supportsTextureShadowLod,
|
||||||
bool supportsViewportMask)
|
bool supportsViewportMask)
|
||||||
{
|
{
|
||||||
@ -27,6 +29,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
SupportsGeometryShaderPassthrough = supportsGeometryShaderPassthrough;
|
SupportsGeometryShaderPassthrough = supportsGeometryShaderPassthrough;
|
||||||
SupportsShaderBallot = supportsShaderBallot;
|
SupportsShaderBallot = supportsShaderBallot;
|
||||||
SupportsShaderBarrierDivergence = supportsShaderBarrierDivergence;
|
SupportsShaderBarrierDivergence = supportsShaderBarrierDivergence;
|
||||||
|
SupportsShaderFloat64 = supportsShaderFloat64;
|
||||||
SupportsTextureShadowLod = supportsTextureShadowLod;
|
SupportsTextureShadowLod = supportsTextureShadowLod;
|
||||||
SupportsViewportMask = supportsViewportMask;
|
SupportsViewportMask = supportsViewportMask;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
// If we can't do bindless elimination, remove the texture operation.
|
// If we can't do bindless elimination, remove the texture operation.
|
||||||
// Set any destination variables to zero.
|
// Set any destination variables to zero.
|
||||||
|
|
||||||
|
string typeName = texOp.Inst.IsImage()
|
||||||
|
? texOp.Type.ToGlslImageType(texOp.Format.GetComponentType())
|
||||||
|
: texOp.Type.ToGlslTextureType();
|
||||||
|
|
||||||
|
gpuAccessor.Log($"Failed to find handle source for bindless access of type \"{typeName}\".");
|
||||||
|
|
||||||
for (int destIndex = 0; destIndex < texOp.DestsCount; destIndex++)
|
for (int destIndex = 0; destIndex < texOp.DestsCount; destIndex++)
|
||||||
{
|
{
|
||||||
block.Operations.AddBefore(node, new Operation(Instruction.Copy, texOp.GetDest(destIndex), OperandHelper.Const(0)));
|
block.Operations.AddBefore(node, new Operation(Instruction.Copy, texOp.GetDest(destIndex), OperandHelper.Const(0)));
|
||||||
@ -62,17 +68,22 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Operand nvHandle = texOp.GetSource(0);
|
Operand bindlessHandle = texOp.GetSource(0);
|
||||||
|
|
||||||
if (nvHandle.AsgOp is not Operation handleOp ||
|
if (bindlessHandle.AsgOp is PhiNode phi)
|
||||||
handleOp.Inst != Instruction.Load ||
|
|
||||||
(handleOp.StorageKind != StorageKind.Input && handleOp.StorageKind != StorageKind.StorageBuffer))
|
|
||||||
{
|
{
|
||||||
// Right now, we only allow bindless access when the handle comes from a shader input or storage buffer.
|
for (int srcIndex = 0; srcIndex < phi.SourcesCount; srcIndex++)
|
||||||
// This is an artificial limitation to prevent it from being used in cases where it
|
{
|
||||||
// would have a large performance impact of loading all textures in the pool.
|
Operand phiSource = phi.GetSource(srcIndex);
|
||||||
// It might be removed in the future, if we can mitigate the performance impact.
|
|
||||||
|
|
||||||
|
if (phiSource.AsgOp is not PhiNode && !IsBindlessAccessAllowed(phiSource))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!IsBindlessAccessAllowed(bindlessHandle))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +91,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
Operand samplerHandle = OperandHelper.Local();
|
Operand samplerHandle = OperandHelper.Local();
|
||||||
Operand textureIndex = OperandHelper.Local();
|
Operand textureIndex = OperandHelper.Local();
|
||||||
|
|
||||||
block.Operations.AddBefore(node, new Operation(Instruction.BitwiseAnd, textureHandle, nvHandle, OperandHelper.Const(0xfffff)));
|
block.Operations.AddBefore(node, new Operation(Instruction.BitwiseAnd, textureHandle, bindlessHandle, OperandHelper.Const(0xfffff)));
|
||||||
block.Operations.AddBefore(node, new Operation(Instruction.ShiftRightU32, samplerHandle, nvHandle, OperandHelper.Const(20)));
|
block.Operations.AddBefore(node, new Operation(Instruction.ShiftRightU32, samplerHandle, bindlessHandle, OperandHelper.Const(20)));
|
||||||
|
|
||||||
int texturePoolLength = Math.Max(BindlessToArray.MinimumArrayLength, gpuAccessor.QueryTextureArrayLengthFromPool());
|
int texturePoolLength = Math.Max(BindlessToArray.MinimumArrayLength, gpuAccessor.QueryTextureArrayLengthFromPool());
|
||||||
|
|
||||||
@ -91,7 +102,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
|
|
||||||
bool hasSampler = !texOp.Inst.IsImage();
|
bool hasSampler = !texOp.Inst.IsImage();
|
||||||
|
|
||||||
int textureBinding = resourceManager.GetTextureOrImageBinding(
|
SetBindingPair textureSetAndBinding = resourceManager.GetTextureOrImageBinding(
|
||||||
texOp.Inst,
|
texOp.Inst,
|
||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
@ -111,7 +122,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
|
|
||||||
texOp.InsertSource(1, samplerIndex);
|
texOp.InsertSource(1, samplerIndex);
|
||||||
|
|
||||||
int samplerBinding = resourceManager.GetTextureOrImageBinding(
|
SetBindingPair samplerSetAndBinding = resourceManager.GetTextureOrImageBinding(
|
||||||
texOp.Inst,
|
texOp.Inst,
|
||||||
SamplerType.None,
|
SamplerType.None,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
@ -120,11 +131,35 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct),
|
TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct),
|
||||||
samplerPoolLength);
|
samplerPoolLength);
|
||||||
|
|
||||||
texOp.TurnIntoArray(textureBinding, samplerBinding);
|
texOp.TurnIntoArray(textureSetAndBinding, samplerSetAndBinding);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
texOp.TurnIntoArray(textureBinding);
|
texOp.TurnIntoArray(textureSetAndBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsBindlessAccessAllowed(Operand bindlessHandle)
|
||||||
|
{
|
||||||
|
if (bindlessHandle.Type == OperandType.ConstantBuffer)
|
||||||
|
{
|
||||||
|
// Bindless access with handles from constant buffer is allowed.
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bindlessHandle.AsgOp is not Operation handleOp ||
|
||||||
|
handleOp.Inst != Instruction.Load ||
|
||||||
|
(handleOp.StorageKind != StorageKind.Input && handleOp.StorageKind != StorageKind.StorageBuffer))
|
||||||
|
{
|
||||||
|
// Right now, we only allow bindless access when the handle comes from a shader input or storage buffer.
|
||||||
|
// This is an artificial limitation to prevent it from being used in cases where it
|
||||||
|
// would have a large performance impact of loading all textures in the pool.
|
||||||
|
// It might be removed in the future, if we can mitigate the performance impact.
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -265,7 +300,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
resourceManager,
|
resourceManager,
|
||||||
gpuAccessor,
|
gpuAccessor,
|
||||||
texOp,
|
texOp,
|
||||||
TextureHandle.PackOffsets(src0.GetCbufOffset(), ((src1.Value >> 20) & 0xfff), handleType),
|
TextureHandle.PackOffsets(src0.GetCbufOffset(), (src1.Value >> 20) & 0xfff, handleType),
|
||||||
TextureHandle.PackSlots(src0.GetCbufSlot(), 0),
|
TextureHandle.PackSlots(src0.GetCbufSlot(), 0),
|
||||||
rewriteSamplerType,
|
rewriteSamplerType,
|
||||||
isImage: false);
|
isImage: false);
|
||||||
@ -445,7 +480,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = resourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = resourceManager.GetTextureOrImageBinding(
|
||||||
texOp.Inst,
|
texOp.Inst,
|
||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
@ -453,7 +488,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
cbufSlot,
|
cbufSlot,
|
||||||
cbufOffset);
|
cbufOffset);
|
||||||
|
|
||||||
texOp.SetBinding(binding);
|
texOp.SetBinding(setAndBinding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texOp.GetSource(0).AsgOp is not Operation handleAsgOp)
|
Operand bindlessHandle = Utils.FindLastOperation(texOp.GetSource(0), block);
|
||||||
|
|
||||||
|
if (bindlessHandle.AsgOp is not Operation handleAsgOp)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -137,8 +139,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
|
|
||||||
if (handleAsgOp.Inst == Instruction.BitwiseOr)
|
if (handleAsgOp.Inst == Instruction.BitwiseOr)
|
||||||
{
|
{
|
||||||
Operand src0 = handleAsgOp.GetSource(0);
|
Operand src0 = Utils.FindLastOperation(handleAsgOp.GetSource(0), block);
|
||||||
Operand src1 = handleAsgOp.GetSource(1);
|
Operand src1 = Utils.FindLastOperation(handleAsgOp.GetSource(1), block);
|
||||||
|
|
||||||
if (src0.Type == OperandType.ConstantBuffer && src1.AsgOp is Operation)
|
if (src0.Type == OperandType.ConstantBuffer && src1.AsgOp is Operation)
|
||||||
{
|
{
|
||||||
@ -221,7 +223,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
|
|
||||||
private static void TurnIntoArray(ResourceManager resourceManager, TextureOperation texOp, int cbufSlot, int handleIndex, int length)
|
private static void TurnIntoArray(ResourceManager resourceManager, TextureOperation texOp, int cbufSlot, int handleIndex, int length)
|
||||||
{
|
{
|
||||||
int binding = resourceManager.GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = resourceManager.GetTextureOrImageBinding(
|
||||||
texOp.Inst,
|
texOp.Inst,
|
||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
@ -230,7 +232,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
handleIndex,
|
handleIndex,
|
||||||
length);
|
length);
|
||||||
|
|
||||||
texOp.TurnIntoArray(binding);
|
texOp.TurnIntoArray(setAndBinding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,18 +152,14 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
{
|
{
|
||||||
// If all phi sources are the same, we can propagate it and remove the phi.
|
// If all phi sources are the same, we can propagate it and remove the phi.
|
||||||
|
|
||||||
Operand firstSrc = phi.GetSource(0);
|
if (!Utils.AreAllSourcesTheSameOperand(phi))
|
||||||
|
|
||||||
for (int index = 1; index < phi.SourcesCount; index++)
|
|
||||||
{
|
{
|
||||||
if (!IsSameOperand(firstSrc, phi.GetSource(index)))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All sources are equal, we can propagate the value.
|
// All sources are equal, we can propagate the value.
|
||||||
|
|
||||||
|
Operand firstSrc = phi.GetSource(0);
|
||||||
Operand dest = phi.Dest;
|
Operand dest = phi.Dest;
|
||||||
|
|
||||||
INode[] uses = dest.UseOps.ToArray();
|
INode[] uses = dest.UseOps.ToArray();
|
||||||
@ -182,17 +178,6 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsSameOperand(Operand x, Operand y)
|
|
||||||
{
|
|
||||||
if (x.Type != y.Type || x.Value != y.Value)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Handle Load operations with the same storage and the same constant parameters.
|
|
||||||
return x.Type == OperandType.Constant || x.Type == OperandType.ConstantBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool PropagatePack(Operation packOp)
|
private static bool PropagatePack(Operation packOp)
|
||||||
{
|
{
|
||||||
// Propagate pack source operands to uses by unpack
|
// Propagate pack source operands to uses by unpack
|
||||||
|
@ -31,6 +31,10 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
TryEliminateBitwiseOr(operation);
|
TryEliminateBitwiseOr(operation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Instruction.CompareNotEqual:
|
||||||
|
TryEliminateCompareNotEqual(operation);
|
||||||
|
break;
|
||||||
|
|
||||||
case Instruction.ConditionalSelect:
|
case Instruction.ConditionalSelect:
|
||||||
TryEliminateConditionalSelect(operation);
|
TryEliminateConditionalSelect(operation);
|
||||||
break;
|
break;
|
||||||
@ -174,6 +178,32 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void TryEliminateCompareNotEqual(Operation operation)
|
||||||
|
{
|
||||||
|
// Comparison instruction returns 0 if the result is false, and -1 if true.
|
||||||
|
// Doing a not equal zero comparison on the result is redundant, so we can just copy the first result in this case.
|
||||||
|
|
||||||
|
Operand lhs = operation.GetSource(0);
|
||||||
|
Operand rhs = operation.GetSource(1);
|
||||||
|
|
||||||
|
if (lhs.Type == OperandType.Constant)
|
||||||
|
{
|
||||||
|
(lhs, rhs) = (rhs, lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rhs.Type != OperandType.Constant || rhs.Value != 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lhs.AsgOp is not Operation compareOp || !compareOp.Inst.IsComparison())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.TurnIntoCopy(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
private static void TryEliminateConditionalSelect(Operation operation)
|
private static void TryEliminateConditionalSelect(Operation operation)
|
||||||
{
|
{
|
||||||
Operand cond = operation.GetSource(0);
|
Operand cond = operation.GetSource(0);
|
||||||
|
@ -34,6 +34,50 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
return elemIndexSrc.Type == OperandType.Constant && elemIndexSrc.Value == elemIndex;
|
return elemIndexSrc.Type == OperandType.Constant && elemIndexSrc.Value == elemIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsSameOperand(Operand x, Operand y)
|
||||||
|
{
|
||||||
|
if (x.Type != y.Type || x.Value != y.Value)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Handle Load operations with the same storage and the same constant parameters.
|
||||||
|
return x == y || x.Type == OperandType.Constant || x.Type == OperandType.ConstantBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool AreAllSourcesEqual(INode node, INode otherNode)
|
||||||
|
{
|
||||||
|
if (node.SourcesCount != otherNode.SourcesCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int index = 0; index < node.SourcesCount; index++)
|
||||||
|
{
|
||||||
|
if (!IsSameOperand(node.GetSource(index), otherNode.GetSource(index)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreAllSourcesTheSameOperand(INode node)
|
||||||
|
{
|
||||||
|
Operand firstSrc = node.GetSource(0);
|
||||||
|
|
||||||
|
for (int index = 1; index < node.SourcesCount; index++)
|
||||||
|
{
|
||||||
|
if (!IsSameOperand(firstSrc, node.GetSource(index)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static Operation FindBranchSource(BasicBlock block)
|
private static Operation FindBranchSource(BasicBlock block)
|
||||||
{
|
{
|
||||||
foreach (BasicBlock sourceBlock in block.Predecessors)
|
foreach (BasicBlock sourceBlock in block.Predecessors)
|
||||||
@ -55,6 +99,19 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
return inst == Instruction.BranchIfFalse || inst == Instruction.BranchIfTrue;
|
return inst == Instruction.BranchIfFalse || inst == Instruction.BranchIfTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsSameCondition(Operand currentCondition, Operand queryCondition)
|
||||||
|
{
|
||||||
|
if (currentCondition == queryCondition)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentCondition.AsgOp is Operation currentOperation &&
|
||||||
|
queryCondition.AsgOp is Operation queryOperation &&
|
||||||
|
currentOperation.Inst == queryOperation.Inst &&
|
||||||
|
AreAllSourcesEqual(currentOperation, queryOperation);
|
||||||
|
}
|
||||||
|
|
||||||
private static bool BlockConditionsMatch(BasicBlock currentBlock, BasicBlock queryBlock)
|
private static bool BlockConditionsMatch(BasicBlock currentBlock, BasicBlock queryBlock)
|
||||||
{
|
{
|
||||||
// Check if all the conditions for the query block are satisfied by the current block.
|
// Check if all the conditions for the query block are satisfied by the current block.
|
||||||
@ -70,10 +127,10 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
|
|
||||||
return currentBranch != null && queryBranch != null &&
|
return currentBranch != null && queryBranch != null &&
|
||||||
currentBranch.Inst == queryBranch.Inst &&
|
currentBranch.Inst == queryBranch.Inst &&
|
||||||
currentCondition == queryCondition;
|
IsSameCondition(currentCondition, queryCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operand FindLastOperation(Operand source, BasicBlock block)
|
public static Operand FindLastOperation(Operand source, BasicBlock block, bool recurse = true)
|
||||||
{
|
{
|
||||||
if (source.AsgOp is PhiNode phiNode)
|
if (source.AsgOp is PhiNode phiNode)
|
||||||
{
|
{
|
||||||
@ -84,10 +141,23 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||||||
for (int i = phiNode.SourcesCount - 1; i >= 0; i--)
|
for (int i = phiNode.SourcesCount - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
BasicBlock phiBlock = phiNode.GetBlock(i);
|
BasicBlock phiBlock = phiNode.GetBlock(i);
|
||||||
|
Operand phiSource = phiNode.GetSource(i);
|
||||||
|
|
||||||
if (BlockConditionsMatch(block, phiBlock))
|
if (BlockConditionsMatch(block, phiBlock))
|
||||||
{
|
{
|
||||||
return phiNode.GetSource(i);
|
return phiSource;
|
||||||
|
}
|
||||||
|
else if (recurse && phiSource.AsgOp is PhiNode)
|
||||||
|
{
|
||||||
|
// Phi source is another phi.
|
||||||
|
// Let's check if that phi has a block that matches our condition.
|
||||||
|
|
||||||
|
Operand match = FindLastOperation(phiSource, block, false);
|
||||||
|
|
||||||
|
if (match != phiSource)
|
||||||
|
{
|
||||||
|
return match;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,14 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
localInputs[block.Index] |= GetMask(register) & ~localOutputs[block.Index];
|
localInputs[block.Index] |= GetMask(register) & ~localOutputs[block.Index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation.Dest != null && operation.Dest.Type == OperandType.Register)
|
for (int dstIndex = 0; dstIndex < operation.DestsCount; dstIndex++)
|
||||||
{
|
{
|
||||||
localOutputs[block.Index] |= GetMask(operation.Dest.GetRegister());
|
Operand dest = operation.GetDest(dstIndex);
|
||||||
|
|
||||||
|
if (dest != null && dest.Type == OperandType.Register)
|
||||||
|
{
|
||||||
|
localOutputs[block.Index] |= GetMask(dest.GetRegister());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
private readonly ShaderStage _stage;
|
private readonly ShaderStage _stage;
|
||||||
private readonly string _stagePrefix;
|
private readonly string _stagePrefix;
|
||||||
|
|
||||||
private readonly int[] _cbSlotToBindingMap;
|
private readonly SetBindingPair[] _cbSlotToBindingMap;
|
||||||
private readonly int[] _sbSlotToBindingMap;
|
private readonly SetBindingPair[] _sbSlotToBindingMap;
|
||||||
private uint _sbSlotWritten;
|
private uint _sbSlotWritten;
|
||||||
|
|
||||||
private readonly Dictionary<int, int> _sbSlots;
|
private readonly Dictionary<int, int> _sbSlots;
|
||||||
@ -33,6 +33,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
private struct TextureMeta
|
private struct TextureMeta
|
||||||
{
|
{
|
||||||
|
public int Set;
|
||||||
public int Binding;
|
public int Binding;
|
||||||
public bool AccurateType;
|
public bool AccurateType;
|
||||||
public SamplerType Type;
|
public SamplerType Type;
|
||||||
@ -64,10 +65,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
_stage = stage;
|
_stage = stage;
|
||||||
_stagePrefix = GetShaderStagePrefix(stage);
|
_stagePrefix = GetShaderStagePrefix(stage);
|
||||||
|
|
||||||
_cbSlotToBindingMap = new int[18];
|
_cbSlotToBindingMap = new SetBindingPair[18];
|
||||||
_sbSlotToBindingMap = new int[16];
|
_sbSlotToBindingMap = new SetBindingPair[16];
|
||||||
_cbSlotToBindingMap.AsSpan().Fill(-1);
|
_cbSlotToBindingMap.AsSpan().Fill(new(-1, -1));
|
||||||
_sbSlotToBindingMap.AsSpan().Fill(-1);
|
_sbSlotToBindingMap.AsSpan().Fill(new(-1, -1));
|
||||||
|
|
||||||
_sbSlots = new();
|
_sbSlots = new();
|
||||||
_sbSlotsReverse = new();
|
_sbSlotsReverse = new();
|
||||||
@ -146,16 +147,16 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
public int GetConstantBufferBinding(int slot)
|
public int GetConstantBufferBinding(int slot)
|
||||||
{
|
{
|
||||||
int binding = _cbSlotToBindingMap[slot];
|
SetBindingPair setAndBinding = _cbSlotToBindingMap[slot];
|
||||||
if (binding < 0)
|
if (setAndBinding.Binding < 0)
|
||||||
{
|
{
|
||||||
binding = _gpuAccessor.CreateConstantBufferBinding(slot);
|
setAndBinding = _gpuAccessor.CreateConstantBufferBinding(slot);
|
||||||
_cbSlotToBindingMap[slot] = binding;
|
_cbSlotToBindingMap[slot] = setAndBinding;
|
||||||
string slotNumber = slot.ToString(CultureInfo.InvariantCulture);
|
string slotNumber = slot.ToString(CultureInfo.InvariantCulture);
|
||||||
AddNewConstantBuffer(binding, $"{_stagePrefix}_c{slotNumber}");
|
AddNewConstantBuffer(setAndBinding.SetIndex, setAndBinding.Binding, $"{_stagePrefix}_c{slotNumber}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding;
|
return setAndBinding.Binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetStorageBufferBinding(int sbCbSlot, int sbCbOffset, bool write, out int binding)
|
public bool TryGetStorageBufferBinding(int sbCbSlot, int sbCbOffset, bool write, out int binding)
|
||||||
@ -166,14 +167,14 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
binding = _sbSlotToBindingMap[slot];
|
SetBindingPair setAndBinding = _sbSlotToBindingMap[slot];
|
||||||
|
|
||||||
if (binding < 0)
|
if (setAndBinding.Binding < 0)
|
||||||
{
|
{
|
||||||
binding = _gpuAccessor.CreateStorageBufferBinding(slot);
|
setAndBinding = _gpuAccessor.CreateStorageBufferBinding(slot);
|
||||||
_sbSlotToBindingMap[slot] = binding;
|
_sbSlotToBindingMap[slot] = setAndBinding;
|
||||||
string slotNumber = slot.ToString(CultureInfo.InvariantCulture);
|
string slotNumber = slot.ToString(CultureInfo.InvariantCulture);
|
||||||
AddNewStorageBuffer(binding, $"{_stagePrefix}_s{slotNumber}");
|
AddNewStorageBuffer(setAndBinding.SetIndex, setAndBinding.Binding, $"{_stagePrefix}_s{slotNumber}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write)
|
if (write)
|
||||||
@ -181,6 +182,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
_sbSlotWritten |= 1u << slot;
|
_sbSlotWritten |= 1u << slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding = setAndBinding.Binding;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
{
|
{
|
||||||
for (slot = 0; slot < _cbSlotToBindingMap.Length; slot++)
|
for (slot = 0; slot < _cbSlotToBindingMap.Length; slot++)
|
||||||
{
|
{
|
||||||
if (_cbSlotToBindingMap[slot] == binding)
|
if (_cbSlotToBindingMap[slot].Binding == binding)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -218,7 +220,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetTextureOrImageBinding(
|
public SetBindingPair GetTextureOrImageBinding(
|
||||||
Instruction inst,
|
Instruction inst,
|
||||||
SamplerType type,
|
SamplerType type,
|
||||||
TextureFormat format,
|
TextureFormat format,
|
||||||
@ -240,7 +242,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
format = TextureFormat.Unknown;
|
format = TextureFormat.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
int binding = GetTextureOrImageBinding(
|
SetBindingPair setAndBinding = GetTextureOrImageBinding(
|
||||||
cbufSlot,
|
cbufSlot,
|
||||||
handle,
|
handle,
|
||||||
arrayLength,
|
arrayLength,
|
||||||
@ -255,10 +257,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
_gpuAccessor.RegisterTexture(handle, cbufSlot);
|
_gpuAccessor.RegisterTexture(handle, cbufSlot);
|
||||||
|
|
||||||
return binding;
|
return setAndBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetTextureOrImageBinding(
|
private SetBindingPair GetTextureOrImageBinding(
|
||||||
int cbufSlot,
|
int cbufSlot,
|
||||||
int handle,
|
int handle,
|
||||||
int arrayLength,
|
int arrayLength,
|
||||||
@ -311,21 +313,38 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
UsageFlags = usageFlags,
|
UsageFlags = usageFlags,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int setIndex;
|
||||||
int binding;
|
int binding;
|
||||||
|
|
||||||
if (dict.TryGetValue(info, out var existingMeta))
|
if (dict.TryGetValue(info, out var existingMeta))
|
||||||
{
|
{
|
||||||
dict[info] = MergeTextureMeta(meta, existingMeta);
|
dict[info] = MergeTextureMeta(meta, existingMeta);
|
||||||
|
setIndex = existingMeta.Set;
|
||||||
binding = existingMeta.Binding;
|
binding = existingMeta.Binding;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool isBuffer = (type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
if (arrayLength > 1 && (setIndex = _gpuAccessor.CreateExtraSet()) >= 0)
|
||||||
|
{
|
||||||
|
// We reserved an "extra set" for the array.
|
||||||
|
// In this case the binding is always the first one (0).
|
||||||
|
// Using separate sets for array is better as we need to do less descriptor set updates.
|
||||||
|
|
||||||
binding = isImage
|
binding = 0;
|
||||||
? _gpuAccessor.CreateImageBinding(arrayLength, isBuffer)
|
}
|
||||||
: _gpuAccessor.CreateTextureBinding(arrayLength, isBuffer);
|
else
|
||||||
|
{
|
||||||
|
bool isBuffer = (type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
||||||
|
|
||||||
|
SetBindingPair setAndBinding = isImage
|
||||||
|
? _gpuAccessor.CreateImageBinding(arrayLength, isBuffer)
|
||||||
|
: _gpuAccessor.CreateTextureBinding(arrayLength, isBuffer);
|
||||||
|
|
||||||
|
setIndex = setAndBinding.SetIndex;
|
||||||
|
binding = setAndBinding.Binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.Set = setIndex;
|
||||||
meta.Binding = binding;
|
meta.Binding = binding;
|
||||||
|
|
||||||
dict.Add(info, meta);
|
dict.Add(info, meta);
|
||||||
@ -355,7 +374,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
}
|
}
|
||||||
|
|
||||||
var definition = new TextureDefinition(
|
var definition = new TextureDefinition(
|
||||||
isImage ? 3 : 2,
|
setIndex,
|
||||||
binding,
|
binding,
|
||||||
arrayLength,
|
arrayLength,
|
||||||
separate,
|
separate,
|
||||||
@ -373,11 +392,12 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
Properties.AddOrUpdateTexture(definition);
|
Properties.AddOrUpdateTexture(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding;
|
return new SetBindingPair(setIndex, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta)
|
private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta)
|
||||||
{
|
{
|
||||||
|
meta.Set = existingMeta.Set;
|
||||||
meta.Binding = existingMeta.Binding;
|
meta.Binding = existingMeta.Binding;
|
||||||
meta.UsageFlags |= existingMeta.UsageFlags;
|
meta.UsageFlags |= existingMeta.UsageFlags;
|
||||||
|
|
||||||
@ -440,11 +460,11 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
for (int slot = 0; slot < _cbSlotToBindingMap.Length; slot++)
|
for (int slot = 0; slot < _cbSlotToBindingMap.Length; slot++)
|
||||||
{
|
{
|
||||||
int binding = _cbSlotToBindingMap[slot];
|
SetBindingPair setAndBinding = _cbSlotToBindingMap[slot];
|
||||||
|
|
||||||
if (binding >= 0 && _usedConstantBufferBindings.Contains(binding))
|
if (setAndBinding.Binding >= 0 && _usedConstantBufferBindings.Contains(setAndBinding.Binding))
|
||||||
{
|
{
|
||||||
descriptors[descriptorIndex++] = new BufferDescriptor(binding, slot);
|
descriptors[descriptorIndex++] = new BufferDescriptor(setAndBinding.SetIndex, setAndBinding.Binding, slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,13 +484,13 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
foreach ((int key, int slot) in _sbSlots)
|
foreach ((int key, int slot) in _sbSlots)
|
||||||
{
|
{
|
||||||
int binding = _sbSlotToBindingMap[slot];
|
SetBindingPair setAndBinding = _sbSlotToBindingMap[slot];
|
||||||
|
|
||||||
if (binding >= 0)
|
if (setAndBinding.Binding >= 0)
|
||||||
{
|
{
|
||||||
(int sbCbSlot, int sbCbOffset) = UnpackSbCbInfo(key);
|
(int sbCbSlot, int sbCbOffset) = UnpackSbCbInfo(key);
|
||||||
BufferUsageFlags flags = (_sbSlotWritten & (1u << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None;
|
BufferUsageFlags flags = (_sbSlotWritten & (1u << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None;
|
||||||
descriptors[descriptorIndex++] = new BufferDescriptor(binding, slot, sbCbSlot, sbCbOffset, flags);
|
descriptors[descriptorIndex++] = new BufferDescriptor(setAndBinding.SetIndex, setAndBinding.Binding, slot, sbCbSlot, sbCbOffset, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,6 +527,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
}
|
}
|
||||||
|
|
||||||
descriptors.Add(new TextureDescriptor(
|
descriptors.Add(new TextureDescriptor(
|
||||||
|
meta.Set,
|
||||||
meta.Binding,
|
meta.Binding,
|
||||||
meta.Type,
|
meta.Type,
|
||||||
info.Format,
|
info.Format,
|
||||||
@ -527,6 +548,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
}
|
}
|
||||||
|
|
||||||
descriptors.Add(new TextureDescriptor(
|
descriptors.Add(new TextureDescriptor(
|
||||||
|
meta.Set,
|
||||||
meta.Binding,
|
meta.Binding,
|
||||||
meta.Type,
|
meta.Type,
|
||||||
info.Format,
|
info.Format,
|
||||||
@ -587,24 +609,24 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddNewConstantBuffer(int binding, string name)
|
private void AddNewConstantBuffer(int setIndex, int binding, string name)
|
||||||
{
|
{
|
||||||
StructureType type = new(new[]
|
StructureType type = new(new[]
|
||||||
{
|
{
|
||||||
new StructureField(AggregateType.Array | AggregateType.Vector4 | AggregateType.FP32, "data", Constants.ConstantBufferSize / 16),
|
new StructureField(AggregateType.Array | AggregateType.Vector4 | AggregateType.FP32, "data", Constants.ConstantBufferSize / 16),
|
||||||
});
|
});
|
||||||
|
|
||||||
Properties.AddOrUpdateConstantBuffer(new(BufferLayout.Std140, 0, binding, name, type));
|
Properties.AddOrUpdateConstantBuffer(new(BufferLayout.Std140, setIndex, binding, name, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddNewStorageBuffer(int binding, string name)
|
private void AddNewStorageBuffer(int setIndex, int binding, string name)
|
||||||
{
|
{
|
||||||
StructureType type = new(new[]
|
StructureType type = new(new[]
|
||||||
{
|
{
|
||||||
new StructureField(AggregateType.Array | AggregateType.U32, "data", 0),
|
new StructureField(AggregateType.Array | AggregateType.U32, "data", 0),
|
||||||
});
|
});
|
||||||
|
|
||||||
Properties.AddOrUpdateStorageBuffer(new(BufferLayout.Std430, 1, binding, name, type));
|
Properties.AddOrUpdateStorageBuffer(new(BufferLayout.Std430, setIndex, binding, name, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetShaderStagePrefix(ShaderStage stage)
|
public static string GetShaderStagePrefix(ShaderStage stage)
|
||||||
|
@ -11,6 +11,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
public const int MaxVertexBufferTextures = 32;
|
public const int MaxVertexBufferTextures = 32;
|
||||||
|
|
||||||
|
private const int TextureSetIndex = 2; // TODO: Get from GPU accessor.
|
||||||
|
|
||||||
public int VertexInfoConstantBufferBinding { get; }
|
public int VertexInfoConstantBufferBinding { get; }
|
||||||
public int VertexOutputStorageBufferBinding { get; }
|
public int VertexOutputStorageBufferBinding { get; }
|
||||||
public int GeometryVertexOutputStorageBufferBinding { get; }
|
public int GeometryVertexOutputStorageBufferBinding { get; }
|
||||||
@ -163,6 +165,21 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
return _vertexBufferTextureBaseBinding + vaLocation;
|
return _vertexBufferTextureBaseBinding + vaLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SetBindingPair GetVertexBufferTextureSetAndBinding(int vaLocation)
|
||||||
|
{
|
||||||
|
return new SetBindingPair(TextureSetIndex, GetVertexBufferTextureBinding(vaLocation));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetBindingPair GetIndexBufferTextureSetAndBinding()
|
||||||
|
{
|
||||||
|
return new SetBindingPair(TextureSetIndex, IndexBufferTextureBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetBindingPair GetTopologyRemapBufferTextureSetAndBinding()
|
||||||
|
{
|
||||||
|
return new SetBindingPair(TextureSetIndex, TopologyRemapBufferTextureBinding);
|
||||||
|
}
|
||||||
|
|
||||||
internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset)
|
internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset)
|
||||||
{
|
{
|
||||||
return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset);
|
return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset);
|
||||||
|
@ -182,6 +182,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags,
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
index,
|
index,
|
||||||
new[] { coordSize },
|
new[] { coordSize },
|
||||||
@ -251,6 +252,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags,
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
index,
|
index,
|
||||||
new[] { coordSize },
|
new[] { coordSize },
|
||||||
@ -471,6 +473,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
|
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
1 << 3, // W component: i=0, j=0
|
1 << 3, // W component: i=0, j=0
|
||||||
new[] { dests[destIndex++] },
|
new[] { dests[destIndex++] },
|
||||||
@ -527,6 +530,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
|
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
componentIndex,
|
componentIndex,
|
||||||
dests,
|
dests,
|
||||||
@ -573,6 +577,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags,
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
index,
|
index,
|
||||||
new[] { texSizes[index] },
|
new[] { texSizes[index] },
|
||||||
@ -603,6 +608,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags,
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
0,
|
0,
|
||||||
new[] { lod },
|
new[] { lod },
|
||||||
@ -633,6 +639,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
texOp.Type,
|
texOp.Type,
|
||||||
texOp.Format,
|
texOp.Format,
|
||||||
texOp.Flags,
|
texOp.Flags,
|
||||||
|
texOp.Set,
|
||||||
texOp.Binding,
|
texOp.Binding,
|
||||||
index,
|
index,
|
||||||
new[] { texSizes[index] },
|
new[] { texSizes[index] },
|
||||||
|
@ -54,6 +54,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
{
|
{
|
||||||
bool needsSextNorm = context.Definitions.IsAttributePackedRgb10A2Signed(location);
|
bool needsSextNorm = context.Definitions.IsAttributePackedRgb10A2Signed(location);
|
||||||
|
|
||||||
|
SetBindingPair setAndBinding = context.ResourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
|
||||||
Operand temp = needsSextNorm ? Local() : dest;
|
Operand temp = needsSextNorm ? Local() : dest;
|
||||||
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, 0);
|
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, 0);
|
||||||
|
|
||||||
@ -62,7 +63,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
SamplerType.TextureBuffer,
|
SamplerType.TextureBuffer,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
TextureFlags.IntCoords,
|
TextureFlags.IntCoords,
|
||||||
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location),
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
1 << component,
|
1 << component,
|
||||||
new[] { temp },
|
new[] { temp },
|
||||||
new[] { vertexElemOffset }));
|
new[] { vertexElemOffset }));
|
||||||
@ -75,6 +77,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
SetBindingPair setAndBinding = context.ResourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
|
||||||
Operand temp = component > 0 ? Local() : dest;
|
Operand temp = component > 0 ? Local() : dest;
|
||||||
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, component);
|
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, component);
|
||||||
|
|
||||||
@ -83,7 +86,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
|
|||||||
SamplerType.TextureBuffer,
|
SamplerType.TextureBuffer,
|
||||||
TextureFormat.Unknown,
|
TextureFormat.Unknown,
|
||||||
TextureFlags.IntCoords,
|
TextureFlags.IntCoords,
|
||||||
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location),
|
setAndBinding.SetIndex,
|
||||||
|
setAndBinding.Binding,
|
||||||
1,
|
1,
|
||||||
new[] { temp },
|
new[] { temp },
|
||||||
new[] { vertexElemOffset }));
|
new[] { vertexElemOffset }));
|
||||||
|
@ -363,6 +363,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
GpuAccessor.QueryHostSupportsGeometryShaderPassthrough(),
|
GpuAccessor.QueryHostSupportsGeometryShaderPassthrough(),
|
||||||
GpuAccessor.QueryHostSupportsShaderBallot(),
|
GpuAccessor.QueryHostSupportsShaderBallot(),
|
||||||
GpuAccessor.QueryHostSupportsShaderBarrierDivergence(),
|
GpuAccessor.QueryHostSupportsShaderBarrierDivergence(),
|
||||||
|
GpuAccessor.QueryHostSupportsShaderFloat64(),
|
||||||
GpuAccessor.QueryHostSupportsTextureShadowLod(),
|
GpuAccessor.QueryHostSupportsTextureShadowLod(),
|
||||||
GpuAccessor.QueryHostSupportsViewportMask());
|
GpuAccessor.QueryHostSupportsViewportMask());
|
||||||
|
|
||||||
@ -412,8 +413,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
|
|
||||||
if (Stage == ShaderStage.Vertex)
|
if (Stage == ShaderStage.Vertex)
|
||||||
{
|
{
|
||||||
int ibBinding = resourceManager.Reservations.IndexBufferTextureBinding;
|
SetBindingPair ibSetAndBinding = resourceManager.Reservations.GetIndexBufferTextureSetAndBinding();
|
||||||
TextureDefinition indexBuffer = new(2, ibBinding, "ib_data", SamplerType.TextureBuffer);
|
TextureDefinition indexBuffer = new(ibSetAndBinding.SetIndex, ibSetAndBinding.Binding, "ib_data", SamplerType.TextureBuffer);
|
||||||
resourceManager.Properties.AddOrUpdateTexture(indexBuffer);
|
resourceManager.Properties.AddOrUpdateTexture(indexBuffer);
|
||||||
|
|
||||||
int inputMap = _program.AttributeUsage.UsedInputAttributes;
|
int inputMap = _program.AttributeUsage.UsedInputAttributes;
|
||||||
@ -421,8 +422,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
while (inputMap != 0)
|
while (inputMap != 0)
|
||||||
{
|
{
|
||||||
int location = BitOperations.TrailingZeroCount(inputMap);
|
int location = BitOperations.TrailingZeroCount(inputMap);
|
||||||
int binding = resourceManager.Reservations.GetVertexBufferTextureBinding(location);
|
SetBindingPair setAndBinding = resourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
|
||||||
TextureDefinition vaBuffer = new(2, binding, $"vb_data{location}", SamplerType.TextureBuffer);
|
TextureDefinition vaBuffer = new(setAndBinding.SetIndex, setAndBinding.Binding, $"vb_data{location}", SamplerType.TextureBuffer);
|
||||||
resourceManager.Properties.AddOrUpdateTexture(vaBuffer);
|
resourceManager.Properties.AddOrUpdateTexture(vaBuffer);
|
||||||
|
|
||||||
inputMap &= ~(1 << location);
|
inputMap &= ~(1 << location);
|
||||||
@ -430,8 +431,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||||||
}
|
}
|
||||||
else if (Stage == ShaderStage.Geometry)
|
else if (Stage == ShaderStage.Geometry)
|
||||||
{
|
{
|
||||||
int trbBinding = resourceManager.Reservations.TopologyRemapBufferTextureBinding;
|
SetBindingPair trbSetAndBinding = resourceManager.Reservations.GetTopologyRemapBufferTextureSetAndBinding();
|
||||||
TextureDefinition remapBuffer = new(2, trbBinding, "trb_data", SamplerType.TextureBuffer);
|
TextureDefinition remapBuffer = new(trbSetAndBinding.SetIndex, trbSetAndBinding.Binding, "trb_data", SamplerType.TextureBuffer);
|
||||||
resourceManager.Properties.AddOrUpdateTexture(remapBuffer);
|
resourceManager.Properties.AddOrUpdateTexture(remapBuffer);
|
||||||
|
|
||||||
int geometryVbOutputSbBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding;
|
int geometryVbOutputSbBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using Ryujinx.Common.Utilities;
|
using Ryujinx.Common.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -293,9 +292,9 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
int depth,
|
int depth,
|
||||||
int levels,
|
int levels,
|
||||||
int layers,
|
int layers,
|
||||||
out IMemoryOwner<byte> decoded)
|
out MemoryOwner<byte> decoded)
|
||||||
{
|
{
|
||||||
decoded = ByteMemoryPool.Rent(QueryDecompressedSize(width, height, depth, levels, layers));
|
decoded = MemoryOwner<byte>.Rent(QueryDecompressedSize(width, height, depth, levels, layers));
|
||||||
|
|
||||||
AstcDecoder decoder = new(data, decoded.Memory, blockWidth, blockHeight, width, height, depth, levels, layers);
|
AstcDecoder decoder = new(data, decoded.Memory, blockWidth, blockHeight, width, height, depth, levels, layers);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
@ -14,7 +13,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
private const int BlockWidth = 4;
|
private const int BlockWidth = 4;
|
||||||
private const int BlockHeight = 4;
|
private const int BlockHeight = 4;
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC1(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeBC1(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -23,12 +22,12 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
||||||
|
|
||||||
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
||||||
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC2(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeBC2(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -111,12 +110,12 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
||||||
|
|
||||||
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
||||||
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC3(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeBC3(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -206,13 +205,13 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
Span<byte> tile = stackalloc byte[BlockWidth * BlockHeight * 4];
|
||||||
Span<byte> rPal = stackalloc byte[8];
|
Span<byte> rPal = stackalloc byte[8];
|
||||||
|
|
||||||
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
Span<uint> tileAsUint = MemoryMarshal.Cast<byte, uint>(tile);
|
||||||
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
Span<Vector128<byte>> tileAsVector128 = MemoryMarshal.Cast<byte, Vector128<byte>>(tile);
|
||||||
|
|
||||||
@ -294,7 +293,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC4(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
public static MemoryOwner<byte> DecodeBC4(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -306,8 +305,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
// Backends currently expect a stride alignment of 4 bytes, so output width must be aligned.
|
// Backends currently expect a stride alignment of 4 bytes, so output width must be aligned.
|
||||||
int alignedWidth = BitUtils.AlignUp(width, 4);
|
int alignedWidth = BitUtils.AlignUp(width, 4);
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
Span<byte> outputSpan = output.Memory.Span;
|
Span<byte> outputSpan = output.Span;
|
||||||
|
|
||||||
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
|
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
@ -402,7 +401,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC5(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
public static MemoryOwner<byte> DecodeBC5(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -414,7 +413,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
// Backends currently expect a stride alignment of 4 bytes, so output width must be aligned.
|
// Backends currently expect a stride alignment of 4 bytes, so output width must be aligned.
|
||||||
int alignedWidth = BitUtils.AlignUp(width, 2);
|
int alignedWidth = BitUtils.AlignUp(width, 2);
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
|
|
||||||
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
|
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
@ -423,7 +422,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
Span<byte> rPal = stackalloc byte[8];
|
Span<byte> rPal = stackalloc byte[8];
|
||||||
Span<byte> gPal = stackalloc byte[8];
|
Span<byte> gPal = stackalloc byte[8];
|
||||||
|
|
||||||
Span<ushort> outputAsUshort = MemoryMarshal.Cast<byte, ushort>(output.Memory.Span);
|
Span<ushort> outputAsUshort = MemoryMarshal.Cast<byte, ushort>(output.Span);
|
||||||
|
|
||||||
Span<uint> rTileAsUint = MemoryMarshal.Cast<byte, uint>(rTile);
|
Span<uint> rTileAsUint = MemoryMarshal.Cast<byte, uint>(rTile);
|
||||||
Span<uint> gTileAsUint = MemoryMarshal.Cast<byte, uint>(gTile);
|
Span<uint> gTileAsUint = MemoryMarshal.Cast<byte, uint>(gTile);
|
||||||
@ -527,7 +526,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC6(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
public static MemoryOwner<byte> DecodeBC6(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers, bool signed)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -536,8 +535,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 8;
|
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
Span<byte> outputSpan = output.Memory.Span;
|
Span<byte> outputSpan = output.Span;
|
||||||
|
|
||||||
int inputOffset = 0;
|
int inputOffset = 0;
|
||||||
int outputOffset = 0;
|
int outputOffset = 0;
|
||||||
@ -566,7 +565,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeBC7(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeBC7(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -575,8 +574,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
size += Math.Max(1, width >> l) * Math.Max(1, height >> l) * Math.Max(1, depth >> l) * layers * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
Span<byte> outputSpan = output.Memory.Span;
|
Span<byte> outputSpan = output.Span;
|
||||||
|
|
||||||
int inputOffset = 0;
|
int inputOffset = 0;
|
||||||
int outputOffset = 0;
|
int outputOffset = 0;
|
||||||
|
@ -2,7 +2,6 @@ using Ryujinx.Common;
|
|||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using Ryujinx.Graphics.Texture.Encoders;
|
using Ryujinx.Graphics.Texture.Encoders;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Texture
|
namespace Ryujinx.Graphics.Texture
|
||||||
{
|
{
|
||||||
@ -11,7 +10,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
private const int BlockWidth = 4;
|
private const int BlockWidth = 4;
|
||||||
private const int BlockHeight = 4;
|
private const int BlockHeight = 4;
|
||||||
|
|
||||||
public static IMemoryOwner<byte> EncodeBC7(Memory<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> EncodeBC7(Memory<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
size += w * h * 16 * Math.Max(1, depth >> l) * layers;
|
size += w * h * 16 * Math.Max(1, depth >> l) * layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(size);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(size);
|
||||||
Memory<byte> outputMemory = output.Memory;
|
Memory<byte> outputMemory = output.Memory;
|
||||||
|
|
||||||
int imageBaseIOffs = 0;
|
int imageBaseIOffs = 0;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
@ -51,15 +50,15 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
new int[] { -3, -5, -7, -9, 2, 4, 6, 8 },
|
new int[] { -3, -5, -7, -9, 2, 4, 6, 8 },
|
||||||
};
|
};
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeRgb(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeRgb(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
int inputOffset = 0;
|
int inputOffset = 0;
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
||||||
|
|
||||||
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
||||||
|
|
||||||
int imageBaseOOffs = 0;
|
int imageBaseOOffs = 0;
|
||||||
@ -113,15 +112,15 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodePta(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodePta(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
int inputOffset = 0;
|
int inputOffset = 0;
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
||||||
|
|
||||||
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
||||||
|
|
||||||
int imageBaseOOffs = 0;
|
int imageBaseOOffs = 0;
|
||||||
@ -170,15 +169,15 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> DecodeRgba(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
public static MemoryOwner<byte> DecodeRgba(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
|
||||||
{
|
{
|
||||||
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
ReadOnlySpan<ulong> dataUlong = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
int inputOffset = 0;
|
int inputOffset = 0;
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(CalculateOutputSize(width, height, depth, levels, layers));
|
||||||
|
|
||||||
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
Span<uint> tile = stackalloc uint[BlockWidth * BlockHeight];
|
||||||
|
|
||||||
int imageBaseOOffs = 0;
|
int imageBaseOOffs = 0;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertBlockLinearToLinear(
|
public static MemoryOwner<byte> ConvertBlockLinearToLinear(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
@ -121,8 +120,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
blockHeight,
|
blockHeight,
|
||||||
bytesPerPixel);
|
bytesPerPixel);
|
||||||
|
|
||||||
IMemoryOwner<byte> outputOwner = ByteMemoryPool.Rent(outSize);
|
MemoryOwner<byte> outputOwner = MemoryOwner<byte>.Rent(outSize);
|
||||||
Span<byte> output = outputOwner.Memory.Span;
|
Span<byte> output = outputOwner.Span;
|
||||||
|
|
||||||
int outOffs = 0;
|
int outOffs = 0;
|
||||||
|
|
||||||
@ -249,7 +248,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return outputOwner;
|
return outputOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertLinearStridedToLinear(
|
public static MemoryOwner<byte> ConvertLinearStridedToLinear(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int blockWidth,
|
int blockWidth,
|
||||||
@ -265,8 +264,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int outStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
int outStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
||||||
lineSize = Math.Min(lineSize, outStride);
|
lineSize = Math.Min(lineSize, outStride);
|
||||||
|
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(h * outStride);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(h * outStride);
|
||||||
Span<byte> outSpan = output.Memory.Span;
|
Span<byte> outSpan = output.Span;
|
||||||
|
|
||||||
int outOffs = 0;
|
int outOffs = 0;
|
||||||
int inOffs = 0;
|
int inOffs = 0;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using Ryujinx.Common.Memory;
|
using Ryujinx.Common.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
@ -21,13 +20,14 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return (remainder, outRemainder, length / stride);
|
return (remainder, outRemainder, length / stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe static IMemoryOwner<byte> ConvertR4G4ToR4G4B4A4(ReadOnlySpan<byte> data, int width)
|
public unsafe static MemoryOwner<byte> ConvertR4G4ToR4G4B4A4(ReadOnlySpan<byte> data, int width)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(data.Length * 2);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(data.Length * 2);
|
||||||
|
Span<byte> outputSpan = output.Span;
|
||||||
|
|
||||||
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 1, 2);
|
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 1, 2);
|
||||||
|
|
||||||
Span<ushort> outputSpan = MemoryMarshal.Cast<byte, ushort>(output.Memory.Span);
|
Span<ushort> outputSpanUInt16 = MemoryMarshal.Cast<byte, ushort>(outputSpan);
|
||||||
|
|
||||||
if (remainder == 0)
|
if (remainder == 0)
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int sizeTrunc = data.Length & ~7;
|
int sizeTrunc = data.Length & ~7;
|
||||||
start = sizeTrunc;
|
start = sizeTrunc;
|
||||||
|
|
||||||
fixed (byte* inputPtr = data, outputPtr = output.Memory.Span)
|
fixed (byte* inputPtr = data, outputPtr = outputSpan)
|
||||||
{
|
{
|
||||||
for (ulong offset = 0; offset < (ulong)sizeTrunc; offset += 8)
|
for (ulong offset = 0; offset < (ulong)sizeTrunc; offset += 8)
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
for (int i = start; i < data.Length; i++)
|
for (int i = start; i < data.Length; i++)
|
||||||
{
|
{
|
||||||
outputSpan[i] = data[i];
|
outputSpanUInt16[i] = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -61,7 +61,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
outputSpan[outOffset++] = data[offset++];
|
outputSpanUInt16[outOffset++] = data[offset++];
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += remainder;
|
offset += remainder;
|
||||||
@ -72,16 +72,16 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertR5G6B5ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
public static MemoryOwner<byte> ConvertR5G6B5ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(data.Length * 2);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(data.Length * 2);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int outOffset = 0;
|
int outOffset = 0;
|
||||||
|
|
||||||
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
||||||
|
|
||||||
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
||||||
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -109,16 +109,16 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertR5G5B5ToR8G8B8A8(ReadOnlySpan<byte> data, int width, bool forceAlpha)
|
public static MemoryOwner<byte> ConvertR5G5B5ToR8G8B8A8(ReadOnlySpan<byte> data, int width, bool forceAlpha)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(data.Length * 2);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(data.Length * 2);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int outOffset = 0;
|
int outOffset = 0;
|
||||||
|
|
||||||
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
||||||
|
|
||||||
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
||||||
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -146,16 +146,16 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertA1B5G5R5ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
public static MemoryOwner<byte> ConvertA1B5G5R5ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(data.Length * 2);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(data.Length * 2);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int outOffset = 0;
|
int outOffset = 0;
|
||||||
|
|
||||||
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
||||||
|
|
||||||
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
||||||
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -183,16 +183,16 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMemoryOwner<byte> ConvertR4G4B4A4ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
public static MemoryOwner<byte> ConvertR4G4B4A4ToR8G8B8A8(ReadOnlySpan<byte> data, int width)
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> output = ByteMemoryPool.Rent(data.Length * 2);
|
MemoryOwner<byte> output = MemoryOwner<byte>.Rent(data.Length * 2);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int outOffset = 0;
|
int outOffset = 0;
|
||||||
|
|
||||||
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
(int remainder, int outRemainder, int height) = GetLineRemainders(data.Length, width, 2, 4);
|
||||||
|
|
||||||
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
ReadOnlySpan<ushort> inputSpan = MemoryMarshal.Cast<byte, ushort>(data);
|
||||||
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Memory.Span);
|
Span<uint> outputSpan = MemoryMarshal.Cast<byte, uint>(output.Span);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,14 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
|
|
||||||
lock (queueLock)
|
lock (queueLock)
|
||||||
{
|
{
|
||||||
_pool = new CommandBufferPool(_gd.Api, _device, queue, queueLock, _gd.QueueFamilyIndex, isLight: true);
|
_pool = new CommandBufferPool(
|
||||||
|
_gd.Api,
|
||||||
|
_device,
|
||||||
|
queue,
|
||||||
|
queueLock,
|
||||||
|
_gd.QueueFamilyIndex,
|
||||||
|
_gd.IsQualcommProprietary,
|
||||||
|
isLight: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Silk.NET.Vulkan;
|
using Silk.NET.Vulkan;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Vulkan
|
namespace Ryujinx.Graphics.Vulkan
|
||||||
{
|
{
|
||||||
@ -8,22 +9,64 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
{
|
{
|
||||||
private const int MaxBarriersPerCall = 16;
|
private const int MaxBarriersPerCall = 16;
|
||||||
|
|
||||||
|
private const AccessFlags BaseAccess = AccessFlags.ShaderReadBit | AccessFlags.ShaderWriteBit;
|
||||||
|
private const AccessFlags BufferAccess = AccessFlags.IndexReadBit | AccessFlags.VertexAttributeReadBit | AccessFlags.UniformReadBit;
|
||||||
|
private const AccessFlags CommandBufferAccess = AccessFlags.IndirectCommandReadBit;
|
||||||
|
|
||||||
private readonly VulkanRenderer _gd;
|
private readonly VulkanRenderer _gd;
|
||||||
|
|
||||||
private readonly NativeArray<MemoryBarrier> _memoryBarrierBatch = new(MaxBarriersPerCall);
|
private readonly NativeArray<MemoryBarrier> _memoryBarrierBatch = new(MaxBarriersPerCall);
|
||||||
private readonly NativeArray<BufferMemoryBarrier> _bufferBarrierBatch = new(MaxBarriersPerCall);
|
private readonly NativeArray<BufferMemoryBarrier> _bufferBarrierBatch = new(MaxBarriersPerCall);
|
||||||
private readonly NativeArray<ImageMemoryBarrier> _imageBarrierBatch = new(MaxBarriersPerCall);
|
private readonly NativeArray<ImageMemoryBarrier> _imageBarrierBatch = new(MaxBarriersPerCall);
|
||||||
|
|
||||||
private readonly List<BarrierWithStageFlags<MemoryBarrier>> _memoryBarriers = new();
|
private readonly List<BarrierWithStageFlags<MemoryBarrier, int>> _memoryBarriers = new();
|
||||||
private readonly List<BarrierWithStageFlags<BufferMemoryBarrier>> _bufferBarriers = new();
|
private readonly List<BarrierWithStageFlags<BufferMemoryBarrier, int>> _bufferBarriers = new();
|
||||||
private readonly List<BarrierWithStageFlags<ImageMemoryBarrier>> _imageBarriers = new();
|
private readonly List<BarrierWithStageFlags<ImageMemoryBarrier, TextureStorage>> _imageBarriers = new();
|
||||||
private int _queuedBarrierCount;
|
private int _queuedBarrierCount;
|
||||||
|
|
||||||
|
private enum IncoherentBarrierType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Texture,
|
||||||
|
All,
|
||||||
|
CommandBuffer
|
||||||
|
}
|
||||||
|
|
||||||
|
private PipelineStageFlags _incoherentBufferWriteStages;
|
||||||
|
private PipelineStageFlags _incoherentTextureWriteStages;
|
||||||
|
private PipelineStageFlags _extraStages;
|
||||||
|
private IncoherentBarrierType _queuedIncoherentBarrier;
|
||||||
|
|
||||||
public BarrierBatch(VulkanRenderer gd)
|
public BarrierBatch(VulkanRenderer gd)
|
||||||
{
|
{
|
||||||
_gd = gd;
|
_gd = gd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static (AccessFlags Access, PipelineStageFlags Stages) GetSubpassAccessSuperset(VulkanRenderer gd)
|
||||||
|
{
|
||||||
|
AccessFlags access = BufferAccess;
|
||||||
|
PipelineStageFlags stages = PipelineStageFlags.AllGraphicsBit;
|
||||||
|
|
||||||
|
if (gd.TransformFeedbackApi != null)
|
||||||
|
{
|
||||||
|
access |= AccessFlags.TransformFeedbackWriteBitExt;
|
||||||
|
stages |= PipelineStageFlags.TransformFeedbackBitExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gd.IsTBDR)
|
||||||
|
{
|
||||||
|
// Desktop GPUs can transform image barriers into memory barriers.
|
||||||
|
|
||||||
|
access |= AccessFlags.DepthStencilAttachmentWriteBit | AccessFlags.ColorAttachmentWriteBit;
|
||||||
|
access |= AccessFlags.DepthStencilAttachmentReadBit | AccessFlags.ColorAttachmentReadBit;
|
||||||
|
|
||||||
|
stages |= PipelineStageFlags.EarlyFragmentTestsBit | PipelineStageFlags.LateFragmentTestsBit;
|
||||||
|
stages |= PipelineStageFlags.ColorAttachmentOutputBit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (access, stages);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly record struct StageFlags : IEquatable<StageFlags>
|
private readonly record struct StageFlags : IEquatable<StageFlags>
|
||||||
{
|
{
|
||||||
public readonly PipelineStageFlags Source;
|
public readonly PipelineStageFlags Source;
|
||||||
@ -36,47 +79,130 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly struct BarrierWithStageFlags<T> where T : unmanaged
|
private readonly struct BarrierWithStageFlags<T, T2> where T : unmanaged
|
||||||
{
|
{
|
||||||
public readonly StageFlags Flags;
|
public readonly StageFlags Flags;
|
||||||
public readonly T Barrier;
|
public readonly T Barrier;
|
||||||
|
public readonly T2 Resource;
|
||||||
|
|
||||||
public BarrierWithStageFlags(StageFlags flags, T barrier)
|
public BarrierWithStageFlags(StageFlags flags, T barrier)
|
||||||
{
|
{
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
Barrier = barrier;
|
Barrier = barrier;
|
||||||
|
Resource = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BarrierWithStageFlags(PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags, T barrier)
|
public BarrierWithStageFlags(PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags, T barrier, T2 resource)
|
||||||
{
|
{
|
||||||
Flags = new StageFlags(srcStageFlags, dstStageFlags);
|
Flags = new StageFlags(srcStageFlags, dstStageFlags);
|
||||||
Barrier = barrier;
|
Barrier = barrier;
|
||||||
|
Resource = resource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void QueueBarrier<T>(List<BarrierWithStageFlags<T>> list, T barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags) where T : unmanaged
|
private void QueueBarrier<T, T2>(List<BarrierWithStageFlags<T, T2>> list, T barrier, T2 resource, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags) where T : unmanaged
|
||||||
{
|
{
|
||||||
list.Add(new BarrierWithStageFlags<T>(srcStageFlags, dstStageFlags, barrier));
|
list.Add(new BarrierWithStageFlags<T, T2>(srcStageFlags, dstStageFlags, barrier, resource));
|
||||||
_queuedBarrierCount++;
|
_queuedBarrierCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueBarrier(MemoryBarrier barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
public void QueueBarrier(MemoryBarrier barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
||||||
{
|
{
|
||||||
QueueBarrier(_memoryBarriers, barrier, srcStageFlags, dstStageFlags);
|
QueueBarrier(_memoryBarriers, barrier, default, srcStageFlags, dstStageFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueBarrier(BufferMemoryBarrier barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
public void QueueBarrier(BufferMemoryBarrier barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
||||||
{
|
{
|
||||||
QueueBarrier(_bufferBarriers, barrier, srcStageFlags, dstStageFlags);
|
QueueBarrier(_bufferBarriers, barrier, default, srcStageFlags, dstStageFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueBarrier(ImageMemoryBarrier barrier, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
public void QueueBarrier(ImageMemoryBarrier barrier, TextureStorage resource, PipelineStageFlags srcStageFlags, PipelineStageFlags dstStageFlags)
|
||||||
{
|
{
|
||||||
QueueBarrier(_imageBarriers, barrier, srcStageFlags, dstStageFlags);
|
QueueBarrier(_imageBarriers, barrier, resource, srcStageFlags, dstStageFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void Flush(CommandBuffer cb, bool insideRenderPass, Action endRenderPass)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public unsafe void FlushMemoryBarrier(ShaderCollection program, bool inRenderPass)
|
||||||
{
|
{
|
||||||
|
if (_queuedIncoherentBarrier > IncoherentBarrierType.None)
|
||||||
|
{
|
||||||
|
// We should emit a memory barrier if there's a write access in the program (current program, or program since last barrier)
|
||||||
|
bool hasTextureWrite = _incoherentTextureWriteStages != PipelineStageFlags.None;
|
||||||
|
bool hasBufferWrite = _incoherentBufferWriteStages != PipelineStageFlags.None;
|
||||||
|
bool hasBufferBarrier = _queuedIncoherentBarrier > IncoherentBarrierType.Texture;
|
||||||
|
|
||||||
|
if (hasTextureWrite || (hasBufferBarrier && hasBufferWrite))
|
||||||
|
{
|
||||||
|
AccessFlags access = BaseAccess;
|
||||||
|
|
||||||
|
PipelineStageFlags stages = inRenderPass ? PipelineStageFlags.AllGraphicsBit : PipelineStageFlags.AllCommandsBit;
|
||||||
|
|
||||||
|
if (hasBufferBarrier && hasBufferWrite)
|
||||||
|
{
|
||||||
|
access |= BufferAccess;
|
||||||
|
|
||||||
|
if (_gd.TransformFeedbackApi != null)
|
||||||
|
{
|
||||||
|
access |= AccessFlags.TransformFeedbackWriteBitExt;
|
||||||
|
stages |= PipelineStageFlags.TransformFeedbackBitExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queuedIncoherentBarrier == IncoherentBarrierType.CommandBuffer)
|
||||||
|
{
|
||||||
|
access |= CommandBufferAccess;
|
||||||
|
stages |= PipelineStageFlags.DrawIndirectBit;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryBarrier barrier = new MemoryBarrier()
|
||||||
|
{
|
||||||
|
SType = StructureType.MemoryBarrier,
|
||||||
|
SrcAccessMask = access,
|
||||||
|
DstAccessMask = access
|
||||||
|
};
|
||||||
|
|
||||||
|
QueueBarrier(barrier, stages, stages);
|
||||||
|
|
||||||
|
_incoherentTextureWriteStages = program?.IncoherentTextureWriteStages ?? PipelineStageFlags.None;
|
||||||
|
|
||||||
|
if (_queuedIncoherentBarrier > IncoherentBarrierType.Texture)
|
||||||
|
{
|
||||||
|
if (program != null)
|
||||||
|
{
|
||||||
|
_incoherentBufferWriteStages = program.IncoherentBufferWriteStages | _extraStages;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_incoherentBufferWriteStages = PipelineStageFlags.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_queuedIncoherentBarrier = IncoherentBarrierType.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void Flush(CommandBufferScoped cbs, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
|
||||||
|
{
|
||||||
|
Flush(cbs, null, inRenderPass, rpHolder, endRenderPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void Flush(CommandBufferScoped cbs, ShaderCollection program, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
|
||||||
|
{
|
||||||
|
if (program != null)
|
||||||
|
{
|
||||||
|
_incoherentBufferWriteStages |= program.IncoherentBufferWriteStages | _extraStages;
|
||||||
|
_incoherentTextureWriteStages |= program.IncoherentTextureWriteStages;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlushMemoryBarrier(program, inRenderPass);
|
||||||
|
|
||||||
|
if (!inRenderPass && rpHolder != null)
|
||||||
|
{
|
||||||
|
// Render pass is about to begin. Queue any fences that normally interrupt the pass.
|
||||||
|
rpHolder.InsertForcedFences(cbs);
|
||||||
|
}
|
||||||
|
|
||||||
while (_queuedBarrierCount > 0)
|
while (_queuedBarrierCount > 0)
|
||||||
{
|
{
|
||||||
int memoryCount = 0;
|
int memoryCount = 0;
|
||||||
@ -86,20 +212,20 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
bool hasBarrier = false;
|
bool hasBarrier = false;
|
||||||
StageFlags flags = default;
|
StageFlags flags = default;
|
||||||
|
|
||||||
static void AddBarriers<T>(
|
static void AddBarriers<T, T2>(
|
||||||
Span<T> target,
|
Span<T> target,
|
||||||
ref int queuedBarrierCount,
|
ref int queuedBarrierCount,
|
||||||
ref bool hasBarrier,
|
ref bool hasBarrier,
|
||||||
ref StageFlags flags,
|
ref StageFlags flags,
|
||||||
ref int count,
|
ref int count,
|
||||||
List<BarrierWithStageFlags<T>> list) where T : unmanaged
|
List<BarrierWithStageFlags<T, T2>> list) where T : unmanaged
|
||||||
{
|
{
|
||||||
int firstMatch = -1;
|
int firstMatch = -1;
|
||||||
int end = list.Count;
|
int end = list.Count;
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i++)
|
for (int i = 0; i < list.Count; i++)
|
||||||
{
|
{
|
||||||
BarrierWithStageFlags<T> barrier = list[i];
|
BarrierWithStageFlags<T, T2> barrier = list[i];
|
||||||
|
|
||||||
if (!hasBarrier)
|
if (!hasBarrier)
|
||||||
{
|
{
|
||||||
@ -162,21 +288,60 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideRenderPass)
|
if (inRenderPass && _imageBarriers.Count > 0)
|
||||||
{
|
{
|
||||||
// Image barriers queued in the batch are meant to be globally scoped,
|
// Image barriers queued in the batch are meant to be globally scoped,
|
||||||
// but inside a render pass they're scoped to just the range of the render pass.
|
// but inside a render pass they're scoped to just the range of the render pass.
|
||||||
|
|
||||||
// On MoltenVK, we just break the rules and always use image barrier.
|
// On MoltenVK, we just break the rules and always use image barrier.
|
||||||
// On desktop GPUs, all barriers are globally scoped, so we just replace it with a generic memory barrier.
|
// On desktop GPUs, all barriers are globally scoped, so we just replace it with a generic memory barrier.
|
||||||
// TODO: On certain GPUs, we need to split render pass so the barrier scope is global. When this is done,
|
// Generally, we want to avoid this from happening in the future, so flag the texture to immediately
|
||||||
// notify the resource that it should add a barrier as soon as a render pass ends to avoid this in future.
|
// emit a barrier whenever the current render pass is bound again.
|
||||||
|
|
||||||
if (!_gd.IsMoltenVk)
|
bool anyIsNonAttachment = false;
|
||||||
|
|
||||||
|
foreach (BarrierWithStageFlags<ImageMemoryBarrier, TextureStorage> barrier in _imageBarriers)
|
||||||
{
|
{
|
||||||
|
// If the binding is an attachment, don't add it as a forced fence.
|
||||||
|
bool isAttachment = rpHolder.ContainsAttachment(barrier.Resource);
|
||||||
|
|
||||||
|
if (!isAttachment)
|
||||||
|
{
|
||||||
|
rpHolder.AddForcedFence(barrier.Resource, barrier.Flags.Dest);
|
||||||
|
anyIsNonAttachment = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_gd.IsTBDR)
|
||||||
|
{
|
||||||
|
if (!_gd.IsMoltenVk)
|
||||||
|
{
|
||||||
|
if (!anyIsNonAttachment)
|
||||||
|
{
|
||||||
|
// This case is a feedback loop. To prevent this from causing an absolute performance disaster,
|
||||||
|
// remove the barriers entirely.
|
||||||
|
// If this is not here, there will be a lot of single draw render passes.
|
||||||
|
// TODO: explicit handling for feedback loops, likely outside this class.
|
||||||
|
|
||||||
|
_queuedBarrierCount -= _imageBarriers.Count;
|
||||||
|
_imageBarriers.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TBDR GPUs are sensitive to barriers, so we need to end the pass to ensure the data is available.
|
||||||
|
// Metal already has hazard tracking so MVK doesn't need this.
|
||||||
|
endRenderPass();
|
||||||
|
inRenderPass = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Generic pipeline memory barriers will work for desktop GPUs.
|
||||||
|
// They do require a few more access flags on the subpass dependency, though.
|
||||||
foreach (var barrier in _imageBarriers)
|
foreach (var barrier in _imageBarriers)
|
||||||
{
|
{
|
||||||
_memoryBarriers.Add(new BarrierWithStageFlags<MemoryBarrier>(
|
_memoryBarriers.Add(new BarrierWithStageFlags<MemoryBarrier, int>(
|
||||||
barrier.Flags,
|
barrier.Flags,
|
||||||
new MemoryBarrier()
|
new MemoryBarrier()
|
||||||
{
|
{
|
||||||
@ -190,6 +355,22 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inRenderPass && _memoryBarriers.Count > 0)
|
||||||
|
{
|
||||||
|
PipelineStageFlags allFlags = PipelineStageFlags.None;
|
||||||
|
|
||||||
|
foreach (var barrier in _memoryBarriers)
|
||||||
|
{
|
||||||
|
allFlags |= barrier.Flags.Dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allFlags.HasFlag(PipelineStageFlags.DrawIndirectBit) || !_gd.SupportsRenderPassBarrier(allFlags))
|
||||||
|
{
|
||||||
|
endRenderPass();
|
||||||
|
inRenderPass = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AddBarriers(_memoryBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref memoryCount, _memoryBarriers);
|
AddBarriers(_memoryBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref memoryCount, _memoryBarriers);
|
||||||
AddBarriers(_bufferBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref bufferCount, _bufferBarriers);
|
AddBarriers(_bufferBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref bufferCount, _bufferBarriers);
|
||||||
AddBarriers(_imageBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref imageCount, _imageBarriers);
|
AddBarriers(_imageBarrierBatch.AsSpan(), ref _queuedBarrierCount, ref hasBarrier, ref flags, ref imageCount, _imageBarriers);
|
||||||
@ -198,14 +379,14 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
{
|
{
|
||||||
PipelineStageFlags srcStageFlags = flags.Source;
|
PipelineStageFlags srcStageFlags = flags.Source;
|
||||||
|
|
||||||
if (insideRenderPass)
|
if (inRenderPass)
|
||||||
{
|
{
|
||||||
// Inside a render pass, barrier stages can only be from rasterization.
|
// Inside a render pass, barrier stages can only be from rasterization.
|
||||||
srcStageFlags &= ~PipelineStageFlags.ComputeShaderBit;
|
srcStageFlags &= ~PipelineStageFlags.ComputeShaderBit;
|
||||||
}
|
}
|
||||||
|
|
||||||
_gd.Api.CmdPipelineBarrier(
|
_gd.Api.CmdPipelineBarrier(
|
||||||
cb,
|
cbs.CommandBuffer,
|
||||||
srcStageFlags,
|
srcStageFlags,
|
||||||
flags.Dest,
|
flags.Dest,
|
||||||
0,
|
0,
|
||||||
@ -219,6 +400,41 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void QueueIncoherentBarrier(IncoherentBarrierType type)
|
||||||
|
{
|
||||||
|
if (type > _queuedIncoherentBarrier)
|
||||||
|
{
|
||||||
|
_queuedIncoherentBarrier = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueueTextureBarrier()
|
||||||
|
{
|
||||||
|
QueueIncoherentBarrier(IncoherentBarrierType.Texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueueMemoryBarrier()
|
||||||
|
{
|
||||||
|
QueueIncoherentBarrier(IncoherentBarrierType.All);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueueCommandBufferBarrier()
|
||||||
|
{
|
||||||
|
QueueIncoherentBarrier(IncoherentBarrierType.CommandBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnableTfbBarriers(bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
_extraStages |= PipelineStageFlags.TransformFeedbackBitExt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_extraStages &= ~PipelineStageFlags.TransformFeedbackBitExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_memoryBarrierBatch.Dispose();
|
_memoryBarrierBatch.Dispose();
|
||||||
|
@ -103,12 +103,19 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
usage |= BufferUsageFlags.IndirectBufferBit;
|
usage |= BufferUsageFlags.IndirectBufferBit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var externalMemoryBuffer = new ExternalMemoryBufferCreateInfo
|
||||||
|
{
|
||||||
|
SType = StructureType.ExternalMemoryBufferCreateInfo,
|
||||||
|
HandleTypes = ExternalMemoryHandleTypeFlags.HostAllocationBitExt,
|
||||||
|
};
|
||||||
|
|
||||||
var bufferCreateInfo = new BufferCreateInfo
|
var bufferCreateInfo = new BufferCreateInfo
|
||||||
{
|
{
|
||||||
SType = StructureType.BufferCreateInfo,
|
SType = StructureType.BufferCreateInfo,
|
||||||
Size = (ulong)size,
|
Size = (ulong)size,
|
||||||
Usage = usage,
|
Usage = usage,
|
||||||
SharingMode = SharingMode.Exclusive,
|
SharingMode = SharingMode.Exclusive,
|
||||||
|
PNext = &externalMemoryBuffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
gd.Api.CreateBuffer(_device, in bufferCreateInfo, null, out var buffer).ThrowOnError();
|
gd.Api.CreateBuffer(_device, in bufferCreateInfo, null, out var buffer).ThrowOnError();
|
||||||
|
@ -18,6 +18,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
private readonly Device _device;
|
private readonly Device _device;
|
||||||
private readonly Queue _queue;
|
private readonly Queue _queue;
|
||||||
private readonly object _queueLock;
|
private readonly object _queueLock;
|
||||||
|
private readonly bool _concurrentFenceWaitUnsupported;
|
||||||
private readonly CommandPool _pool;
|
private readonly CommandPool _pool;
|
||||||
private readonly Thread _owner;
|
private readonly Thread _owner;
|
||||||
|
|
||||||
@ -30,11 +31,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
public int SubmissionCount;
|
public int SubmissionCount;
|
||||||
public CommandBuffer CommandBuffer;
|
public CommandBuffer CommandBuffer;
|
||||||
public FenceHolder Fence;
|
public FenceHolder Fence;
|
||||||
public SemaphoreHolder Semaphore;
|
|
||||||
|
|
||||||
public List<IAuto> Dependants;
|
public List<IAuto> Dependants;
|
||||||
public List<MultiFenceHolder> Waitables;
|
public List<MultiFenceHolder> Waitables;
|
||||||
public HashSet<SemaphoreHolder> Dependencies;
|
|
||||||
|
|
||||||
public void Initialize(Vk api, Device device, CommandPool pool)
|
public void Initialize(Vk api, Device device, CommandPool pool)
|
||||||
{
|
{
|
||||||
@ -50,7 +49,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
|
|
||||||
Dependants = new List<IAuto>();
|
Dependants = new List<IAuto>();
|
||||||
Waitables = new List<MultiFenceHolder>();
|
Waitables = new List<MultiFenceHolder>();
|
||||||
Dependencies = new HashSet<SemaphoreHolder>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +59,20 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
private int _queuedCount;
|
private int _queuedCount;
|
||||||
private int _inUseCount;
|
private int _inUseCount;
|
||||||
|
|
||||||
public unsafe CommandBufferPool(Vk api, Device device, Queue queue, object queueLock, uint queueFamilyIndex, bool isLight = false)
|
public unsafe CommandBufferPool(
|
||||||
|
Vk api,
|
||||||
|
Device device,
|
||||||
|
Queue queue,
|
||||||
|
object queueLock,
|
||||||
|
uint queueFamilyIndex,
|
||||||
|
bool concurrentFenceWaitUnsupported,
|
||||||
|
bool isLight = false)
|
||||||
{
|
{
|
||||||
_api = api;
|
_api = api;
|
||||||
_device = device;
|
_device = device;
|
||||||
_queue = queue;
|
_queue = queue;
|
||||||
_queueLock = queueLock;
|
_queueLock = queueLock;
|
||||||
|
_concurrentFenceWaitUnsupported = concurrentFenceWaitUnsupported;
|
||||||
_owner = Thread.CurrentThread;
|
_owner = Thread.CurrentThread;
|
||||||
|
|
||||||
var commandPoolCreateInfo = new CommandPoolCreateInfo
|
var commandPoolCreateInfo = new CommandPoolCreateInfo
|
||||||
@ -134,14 +140,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddDependency(int cbIndex, CommandBufferScoped dependencyCbs)
|
|
||||||
{
|
|
||||||
Debug.Assert(_commandBuffers[cbIndex].InUse);
|
|
||||||
var semaphoreHolder = _commandBuffers[dependencyCbs.CommandBufferIndex].Semaphore;
|
|
||||||
semaphoreHolder.Get();
|
|
||||||
_commandBuffers[cbIndex].Dependencies.Add(semaphoreHolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddWaitable(int cbIndex, MultiFenceHolder waitable)
|
public void AddWaitable(int cbIndex, MultiFenceHolder waitable)
|
||||||
{
|
{
|
||||||
ref var entry = ref _commandBuffers[cbIndex];
|
ref var entry = ref _commandBuffers[cbIndex];
|
||||||
@ -345,19 +343,13 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
waitable.RemoveBufferUses(cbIndex);
|
waitable.RemoveBufferUses(cbIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var dependency in entry.Dependencies)
|
|
||||||
{
|
|
||||||
dependency.Put();
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.Dependants.Clear();
|
entry.Dependants.Clear();
|
||||||
entry.Waitables.Clear();
|
entry.Waitables.Clear();
|
||||||
entry.Dependencies.Clear();
|
|
||||||
entry.Fence?.Dispose();
|
entry.Fence?.Dispose();
|
||||||
|
|
||||||
if (refreshFence)
|
if (refreshFence)
|
||||||
{
|
{
|
||||||
entry.Fence = new FenceHolder(_api, _device);
|
entry.Fence = new FenceHolder(_api, _device, _concurrentFenceWaitUnsupported);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -26,11 +26,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
_pool.AddWaitable(CommandBufferIndex, waitable);
|
_pool.AddWaitable(CommandBufferIndex, waitable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddDependency(CommandBufferScoped dependencyCbs)
|
|
||||||
{
|
|
||||||
_pool.AddDependency(CommandBufferIndex, dependencyCbs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FenceHolder GetFence()
|
public FenceHolder GetFence()
|
||||||
{
|
{
|
||||||
return _pool.GetFence(CommandBufferIndex);
|
return _pool.GetFence(CommandBufferIndex);
|
||||||
|
@ -69,21 +69,10 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record struct ArrayRef<T>
|
private readonly record struct ArrayRef<T>(ShaderStage Stage, T Array);
|
||||||
{
|
|
||||||
public ShaderStage Stage;
|
|
||||||
public T Array;
|
|
||||||
|
|
||||||
public ArrayRef(ShaderStage stage, T array)
|
|
||||||
{
|
|
||||||
Stage = stage;
|
|
||||||
Array = array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly VulkanRenderer _gd;
|
private readonly VulkanRenderer _gd;
|
||||||
private readonly Device _device;
|
private readonly Device _device;
|
||||||
private readonly PipelineBase _pipeline;
|
|
||||||
private ShaderCollection _program;
|
private ShaderCollection _program;
|
||||||
|
|
||||||
private readonly BufferRef[] _uniformBufferRefs;
|
private readonly BufferRef[] _uniformBufferRefs;
|
||||||
@ -97,6 +86,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
private ArrayRef<TextureArray>[] _textureArrayRefs;
|
private ArrayRef<TextureArray>[] _textureArrayRefs;
|
||||||
private ArrayRef<ImageArray>[] _imageArrayRefs;
|
private ArrayRef<ImageArray>[] _imageArrayRefs;
|
||||||
|
|
||||||
|
private ArrayRef<TextureArray>[] _textureArrayExtraRefs;
|
||||||
|
private ArrayRef<ImageArray>[] _imageArrayExtraRefs;
|
||||||
|
|
||||||
private readonly DescriptorBufferInfo[] _uniformBuffers;
|
private readonly DescriptorBufferInfo[] _uniformBuffers;
|
||||||
private readonly DescriptorBufferInfo[] _storageBuffers;
|
private readonly DescriptorBufferInfo[] _storageBuffers;
|
||||||
private readonly DescriptorImageInfo[] _textures;
|
private readonly DescriptorImageInfo[] _textures;
|
||||||
@ -132,11 +124,10 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
private readonly TextureView _dummyTexture;
|
private readonly TextureView _dummyTexture;
|
||||||
private readonly SamplerHolder _dummySampler;
|
private readonly SamplerHolder _dummySampler;
|
||||||
|
|
||||||
public DescriptorSetUpdater(VulkanRenderer gd, Device device, PipelineBase pipeline)
|
public DescriptorSetUpdater(VulkanRenderer gd, Device device)
|
||||||
{
|
{
|
||||||
_gd = gd;
|
_gd = gd;
|
||||||
_device = device;
|
_device = device;
|
||||||
_pipeline = pipeline;
|
|
||||||
|
|
||||||
// Some of the bindings counts needs to be multiplied by 2 because we have buffer and
|
// Some of the bindings counts needs to be multiplied by 2 because we have buffer and
|
||||||
// regular textures/images interleaved on the same descriptor set.
|
// regular textures/images interleaved on the same descriptor set.
|
||||||
@ -152,6 +143,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
_textureArrayRefs = Array.Empty<ArrayRef<TextureArray>>();
|
_textureArrayRefs = Array.Empty<ArrayRef<TextureArray>>();
|
||||||
_imageArrayRefs = Array.Empty<ArrayRef<ImageArray>>();
|
_imageArrayRefs = Array.Empty<ArrayRef<ImageArray>>();
|
||||||
|
|
||||||
|
_textureArrayExtraRefs = Array.Empty<ArrayRef<TextureArray>>();
|
||||||
|
_imageArrayExtraRefs = Array.Empty<ArrayRef<ImageArray>>();
|
||||||
|
|
||||||
_uniformBuffers = new DescriptorBufferInfo[Constants.MaxUniformBufferBindings];
|
_uniformBuffers = new DescriptorBufferInfo[Constants.MaxUniformBufferBindings];
|
||||||
_storageBuffers = new DescriptorBufferInfo[Constants.MaxStorageBufferBindings];
|
_storageBuffers = new DescriptorBufferInfo[Constants.MaxStorageBufferBindings];
|
||||||
_textures = new DescriptorImageInfo[Constants.MaxTexturesPerStage];
|
_textures = new DescriptorImageInfo[Constants.MaxTexturesPerStage];
|
||||||
@ -217,7 +211,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
IMemoryOwner<byte> dummyTextureData = ByteMemoryPool.RentCleared(4);
|
MemoryOwner<byte> dummyTextureData = MemoryOwner<byte>.RentCleared(4);
|
||||||
_dummyTexture.SetData(dummyTextureData);
|
_dummyTexture.SetData(dummyTextureData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,8 +289,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PipelineStageFlags stageFlags = _textureArrayRefs[segment.Binding].Stage.ConvertToPipelineStageFlags();
|
ref var arrayRef = ref _textureArrayRefs[segment.Binding];
|
||||||
_textureArrayRefs[segment.Binding].Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
PipelineStageFlags stageFlags = arrayRef.Stage.ConvertToPipelineStageFlags();
|
||||||
|
arrayRef.Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,8 +310,40 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PipelineStageFlags stageFlags = _imageArrayRefs[segment.Binding].Stage.ConvertToPipelineStageFlags();
|
ref var arrayRef = ref _imageArrayRefs[segment.Binding];
|
||||||
_imageArrayRefs[segment.Binding].Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
PipelineStageFlags stageFlags = arrayRef.Stage.ConvertToPipelineStageFlags();
|
||||||
|
arrayRef.Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int setIndex = PipelineBase.DescriptorSetLayouts; setIndex < _program.BindingSegments.Length; setIndex++)
|
||||||
|
{
|
||||||
|
var bindingSegments = _program.BindingSegments[setIndex];
|
||||||
|
|
||||||
|
if (bindingSegments.Length == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceBindingSegment segment = bindingSegments[0];
|
||||||
|
|
||||||
|
if (segment.IsArray)
|
||||||
|
{
|
||||||
|
if (segment.Type == ResourceType.Texture ||
|
||||||
|
segment.Type == ResourceType.Sampler ||
|
||||||
|
segment.Type == ResourceType.TextureAndSampler ||
|
||||||
|
segment.Type == ResourceType.BufferTexture)
|
||||||
|
{
|
||||||
|
ref var arrayRef = ref _textureArrayExtraRefs[setIndex - PipelineBase.DescriptorSetLayouts];
|
||||||
|
PipelineStageFlags stageFlags = arrayRef.Stage.ConvertToPipelineStageFlags();
|
||||||
|
arrayRef.Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
||||||
|
}
|
||||||
|
else if (segment.Type == ResourceType.Image || segment.Type == ResourceType.BufferImage)
|
||||||
|
{
|
||||||
|
ref var arrayRef = ref _imageArrayExtraRefs[setIndex - PipelineBase.DescriptorSetLayouts];
|
||||||
|
PipelineStageFlags stageFlags = arrayRef.Stage.ConvertToPipelineStageFlags();
|
||||||
|
arrayRef.Array?.QueueWriteToReadBarriers(cbs, stageFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,25 +522,39 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
|
|
||||||
public void SetTextureArray(CommandBufferScoped cbs, ShaderStage stage, int binding, ITextureArray array)
|
public void SetTextureArray(CommandBufferScoped cbs, ShaderStage stage, int binding, ITextureArray array)
|
||||||
{
|
{
|
||||||
if (_textureArrayRefs.Length <= binding)
|
ref ArrayRef<TextureArray> arrayRef = ref GetArrayRef(ref _textureArrayRefs, binding, ArrayGrowthSize);
|
||||||
{
|
|
||||||
Array.Resize(ref _textureArrayRefs, binding + ArrayGrowthSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_textureArrayRefs[binding].Stage != stage || _textureArrayRefs[binding].Array != array)
|
if (arrayRef.Stage != stage || arrayRef.Array != array)
|
||||||
{
|
{
|
||||||
if (_textureArrayRefs[binding].Array != null)
|
arrayRef.Array?.DecrementBindCount();
|
||||||
{
|
|
||||||
_textureArrayRefs[binding].Array.Bound = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array is TextureArray textureArray)
|
if (array is TextureArray textureArray)
|
||||||
{
|
{
|
||||||
textureArray.Bound = true;
|
textureArray.IncrementBindCount();
|
||||||
textureArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
textureArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
_textureArrayRefs[binding] = new ArrayRef<TextureArray>(stage, array as TextureArray);
|
arrayRef = new ArrayRef<TextureArray>(stage, array as TextureArray);
|
||||||
|
|
||||||
|
SignalDirty(DirtyFlags.Texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTextureArraySeparate(CommandBufferScoped cbs, ShaderStage stage, int setIndex, ITextureArray array)
|
||||||
|
{
|
||||||
|
ref ArrayRef<TextureArray> arrayRef = ref GetArrayRef(ref _textureArrayExtraRefs, setIndex - PipelineBase.DescriptorSetLayouts);
|
||||||
|
|
||||||
|
if (arrayRef.Stage != stage || arrayRef.Array != array)
|
||||||
|
{
|
||||||
|
arrayRef.Array?.DecrementBindCount();
|
||||||
|
|
||||||
|
if (array is TextureArray textureArray)
|
||||||
|
{
|
||||||
|
textureArray.IncrementBindCount();
|
||||||
|
textureArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayRef = new ArrayRef<TextureArray>(stage, array as TextureArray);
|
||||||
|
|
||||||
SignalDirty(DirtyFlags.Texture);
|
SignalDirty(DirtyFlags.Texture);
|
||||||
}
|
}
|
||||||
@ -521,30 +562,56 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
|
|
||||||
public void SetImageArray(CommandBufferScoped cbs, ShaderStage stage, int binding, IImageArray array)
|
public void SetImageArray(CommandBufferScoped cbs, ShaderStage stage, int binding, IImageArray array)
|
||||||
{
|
{
|
||||||
if (_imageArrayRefs.Length <= binding)
|
ref ArrayRef<ImageArray> arrayRef = ref GetArrayRef(ref _imageArrayRefs, binding, ArrayGrowthSize);
|
||||||
{
|
|
||||||
Array.Resize(ref _imageArrayRefs, binding + ArrayGrowthSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_imageArrayRefs[binding].Stage != stage || _imageArrayRefs[binding].Array != array)
|
if (arrayRef.Stage != stage || arrayRef.Array != array)
|
||||||
{
|
{
|
||||||
if (_imageArrayRefs[binding].Array != null)
|
arrayRef.Array?.DecrementBindCount();
|
||||||
{
|
|
||||||
_imageArrayRefs[binding].Array.Bound = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array is ImageArray imageArray)
|
if (array is ImageArray imageArray)
|
||||||
{
|
{
|
||||||
imageArray.Bound = true;
|
imageArray.IncrementBindCount();
|
||||||
imageArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
imageArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageArrayRefs[binding] = new ArrayRef<ImageArray>(stage, array as ImageArray);
|
arrayRef = new ArrayRef<ImageArray>(stage, array as ImageArray);
|
||||||
|
|
||||||
SignalDirty(DirtyFlags.Image);
|
SignalDirty(DirtyFlags.Image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetImageArraySeparate(CommandBufferScoped cbs, ShaderStage stage, int setIndex, IImageArray array)
|
||||||
|
{
|
||||||
|
ref ArrayRef<ImageArray> arrayRef = ref GetArrayRef(ref _imageArrayExtraRefs, setIndex - PipelineBase.DescriptorSetLayouts);
|
||||||
|
|
||||||
|
if (arrayRef.Stage != stage || arrayRef.Array != array)
|
||||||
|
{
|
||||||
|
arrayRef.Array?.DecrementBindCount();
|
||||||
|
|
||||||
|
if (array is ImageArray imageArray)
|
||||||
|
{
|
||||||
|
imageArray.IncrementBindCount();
|
||||||
|
imageArray.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayRef = new ArrayRef<ImageArray>(stage, array as ImageArray);
|
||||||
|
|
||||||
|
SignalDirty(DirtyFlags.Image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ref ArrayRef<T> GetArrayRef<T>(ref ArrayRef<T>[] array, int index, int growthSize = 1)
|
||||||
|
{
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
||||||
|
|
||||||
|
if (array.Length <= index)
|
||||||
|
{
|
||||||
|
Array.Resize(ref array, index + growthSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ref array[index];
|
||||||
|
}
|
||||||
|
|
||||||
public void SetUniformBuffers(CommandBuffer commandBuffer, ReadOnlySpan<BufferAssignment> buffers)
|
public void SetUniformBuffers(CommandBuffer commandBuffer, ReadOnlySpan<BufferAssignment> buffers)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buffers.Length; i++)
|
for (int i = 0; i < buffers.Length; i++)
|
||||||
@ -594,31 +661,47 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var program = _program;
|
||||||
|
|
||||||
if (_dirty.HasFlag(DirtyFlags.Uniform))
|
if (_dirty.HasFlag(DirtyFlags.Uniform))
|
||||||
{
|
{
|
||||||
if (_program.UsePushDescriptors)
|
if (program.UsePushDescriptors)
|
||||||
{
|
{
|
||||||
UpdateAndBindUniformBufferPd(cbs, pbp);
|
UpdateAndBindUniformBufferPd(cbs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UpdateAndBind(cbs, PipelineBase.UniformSetIndex, pbp);
|
UpdateAndBind(cbs, program, PipelineBase.UniformSetIndex, pbp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dirty.HasFlag(DirtyFlags.Storage))
|
if (_dirty.HasFlag(DirtyFlags.Storage))
|
||||||
{
|
{
|
||||||
UpdateAndBind(cbs, PipelineBase.StorageSetIndex, pbp);
|
UpdateAndBind(cbs, program, PipelineBase.StorageSetIndex, pbp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dirty.HasFlag(DirtyFlags.Texture))
|
if (_dirty.HasFlag(DirtyFlags.Texture))
|
||||||
{
|
{
|
||||||
UpdateAndBind(cbs, PipelineBase.TextureSetIndex, pbp);
|
if (program.UpdateTexturesWithoutTemplate)
|
||||||
|
{
|
||||||
|
UpdateAndBindTexturesWithoutTemplate(cbs, program, pbp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateAndBind(cbs, program, PipelineBase.TextureSetIndex, pbp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dirty.HasFlag(DirtyFlags.Image))
|
if (_dirty.HasFlag(DirtyFlags.Image))
|
||||||
{
|
{
|
||||||
UpdateAndBind(cbs, PipelineBase.ImageSetIndex, pbp);
|
UpdateAndBind(cbs, program, PipelineBase.ImageSetIndex, pbp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (program.BindingSegments.Length > PipelineBase.DescriptorSetLayouts)
|
||||||
|
{
|
||||||
|
// Program is using extra sets, we need to bind those too.
|
||||||
|
|
||||||
|
BindExtraSets(cbs, program, pbp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirty = DirtyFlags.None;
|
_dirty = DirtyFlags.None;
|
||||||
@ -658,9 +741,8 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void UpdateAndBind(CommandBufferScoped cbs, int setIndex, PipelineBindPoint pbp)
|
private void UpdateAndBind(CommandBufferScoped cbs, ShaderCollection program, int setIndex, PipelineBindPoint pbp)
|
||||||
{
|
{
|
||||||
var program = _program;
|
|
||||||
var bindingSegments = program.BindingSegments[setIndex];
|
var bindingSegments = program.BindingSegments[setIndex];
|
||||||
|
|
||||||
if (bindingSegments.Length == 0)
|
if (bindingSegments.Length == 0)
|
||||||
@ -841,35 +923,88 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
_gd.Api.CmdBindDescriptorSets(cbs.CommandBuffer, pbp, _program.PipelineLayout, (uint)setIndex, 1, sets, 0, ReadOnlySpan<uint>.Empty);
|
_gd.Api.CmdBindDescriptorSets(cbs.CommandBuffer, pbp, _program.PipelineLayout, (uint)setIndex, 1, sets, 0, ReadOnlySpan<uint>.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void UpdateBuffers(
|
private void UpdateAndBindTexturesWithoutTemplate(CommandBufferScoped cbs, ShaderCollection program, PipelineBindPoint pbp)
|
||||||
CommandBufferScoped cbs,
|
|
||||||
PipelineBindPoint pbp,
|
|
||||||
int baseBinding,
|
|
||||||
ReadOnlySpan<DescriptorBufferInfo> bufferInfo,
|
|
||||||
DescriptorType type)
|
|
||||||
{
|
{
|
||||||
if (bufferInfo.Length == 0)
|
int setIndex = PipelineBase.TextureSetIndex;
|
||||||
|
var bindingSegments = program.BindingSegments[setIndex];
|
||||||
|
|
||||||
|
if (bindingSegments.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (DescriptorBufferInfo* pBufferInfo = bufferInfo)
|
if (_updateDescriptorCacheCbIndex)
|
||||||
{
|
{
|
||||||
var writeDescriptorSet = new WriteDescriptorSet
|
_updateDescriptorCacheCbIndex = false;
|
||||||
{
|
program.UpdateDescriptorCacheCommandBufferIndex(cbs.CommandBufferIndex);
|
||||||
SType = StructureType.WriteDescriptorSet,
|
|
||||||
DstBinding = (uint)baseBinding,
|
|
||||||
DescriptorType = type,
|
|
||||||
DescriptorCount = (uint)bufferInfo.Length,
|
|
||||||
PBufferInfo = pBufferInfo,
|
|
||||||
};
|
|
||||||
|
|
||||||
_gd.PushDescriptorApi.CmdPushDescriptorSet(cbs.CommandBuffer, pbp, _program.PipelineLayout, 0, 1, &writeDescriptorSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dsc = program.GetNewDescriptorSetCollection(setIndex, out _).Get(cbs);
|
||||||
|
|
||||||
|
foreach (ResourceBindingSegment segment in bindingSegments)
|
||||||
|
{
|
||||||
|
int binding = segment.Binding;
|
||||||
|
int count = segment.Count;
|
||||||
|
|
||||||
|
if (!segment.IsArray)
|
||||||
|
{
|
||||||
|
if (segment.Type != ResourceType.BufferTexture)
|
||||||
|
{
|
||||||
|
Span<DescriptorImageInfo> textures = _textures;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
ref var texture = ref textures[i];
|
||||||
|
ref var refs = ref _textureRefs[binding + i];
|
||||||
|
|
||||||
|
texture.ImageView = refs.View?.Get(cbs).Value ?? default;
|
||||||
|
texture.Sampler = refs.Sampler?.Get(cbs).Value ?? default;
|
||||||
|
|
||||||
|
if (texture.ImageView.Handle == 0)
|
||||||
|
{
|
||||||
|
texture.ImageView = _dummyTexture.GetImageView().Get(cbs).Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture.Sampler.Handle == 0)
|
||||||
|
{
|
||||||
|
texture.Sampler = _dummySampler.GetSampler().Get(cbs).Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dsc.UpdateImages(0, binding, textures[..count], DescriptorType.CombinedImageSampler);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Span<BufferView> bufferTextures = _bufferTextures;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
bufferTextures[i] = _bufferTextureRefs[binding + i]?.GetBufferView(cbs, false) ?? default;
|
||||||
|
}
|
||||||
|
|
||||||
|
dsc.UpdateBufferImages(0, binding, bufferTextures[..count], DescriptorType.UniformTexelBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (segment.Type != ResourceType.BufferTexture)
|
||||||
|
{
|
||||||
|
dsc.UpdateImages(0, binding, _textureArrayRefs[binding].Array.GetImageInfos(_gd, cbs, _dummyTexture, _dummySampler), DescriptorType.CombinedImageSampler);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dsc.UpdateBufferImages(0, binding, _textureArrayRefs[binding].Array.GetBufferViews(cbs), DescriptorType.UniformTexelBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sets = dsc.GetSets();
|
||||||
|
|
||||||
|
_gd.Api.CmdBindDescriptorSets(cbs.CommandBuffer, pbp, _program.PipelineLayout, (uint)setIndex, 1, sets, 0, ReadOnlySpan<uint>.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void UpdateAndBindUniformBufferPd(CommandBufferScoped cbs, PipelineBindPoint pbp)
|
private void UpdateAndBindUniformBufferPd(CommandBufferScoped cbs)
|
||||||
{
|
{
|
||||||
int sequence = _pdSequence;
|
int sequence = _pdSequence;
|
||||||
var bindingSegments = _program.BindingSegments[PipelineBase.UniformSetIndex];
|
var bindingSegments = _program.BindingSegments[PipelineBase.UniformSetIndex];
|
||||||
@ -933,6 +1068,56 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BindExtraSets(CommandBufferScoped cbs, ShaderCollection program, PipelineBindPoint pbp)
|
||||||
|
{
|
||||||
|
for (int setIndex = PipelineBase.DescriptorSetLayouts; setIndex < program.BindingSegments.Length; setIndex++)
|
||||||
|
{
|
||||||
|
var bindingSegments = program.BindingSegments[setIndex];
|
||||||
|
|
||||||
|
if (bindingSegments.Length == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceBindingSegment segment = bindingSegments[0];
|
||||||
|
|
||||||
|
if (segment.IsArray)
|
||||||
|
{
|
||||||
|
DescriptorSet[] sets = null;
|
||||||
|
|
||||||
|
if (segment.Type == ResourceType.Texture ||
|
||||||
|
segment.Type == ResourceType.Sampler ||
|
||||||
|
segment.Type == ResourceType.TextureAndSampler ||
|
||||||
|
segment.Type == ResourceType.BufferTexture)
|
||||||
|
{
|
||||||
|
sets = _textureArrayExtraRefs[setIndex - PipelineBase.DescriptorSetLayouts].Array.GetDescriptorSets(
|
||||||
|
_device,
|
||||||
|
cbs,
|
||||||
|
_templateUpdater,
|
||||||
|
program,
|
||||||
|
setIndex,
|
||||||
|
_dummyTexture,
|
||||||
|
_dummySampler);
|
||||||
|
}
|
||||||
|
else if (segment.Type == ResourceType.Image || segment.Type == ResourceType.BufferImage)
|
||||||
|
{
|
||||||
|
sets = _imageArrayExtraRefs[setIndex - PipelineBase.DescriptorSetLayouts].Array.GetDescriptorSets(
|
||||||
|
_device,
|
||||||
|
cbs,
|
||||||
|
_templateUpdater,
|
||||||
|
program,
|
||||||
|
setIndex,
|
||||||
|
_dummyTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sets != null)
|
||||||
|
{
|
||||||
|
_gd.Api.CmdBindDescriptorSets(cbs.CommandBuffer, pbp, _program.PipelineLayout, (uint)setIndex, 1, sets, 0, ReadOnlySpan<uint>.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SignalCommandBufferChange()
|
public void SignalCommandBufferChange()
|
||||||
{
|
{
|
||||||
_updateDescriptorCacheCbIndex = true;
|
_updateDescriptorCacheCbIndex = true;
|
||||||
|
@ -59,14 +59,14 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||||||
var scalingResourceLayout = new ResourceLayoutBuilder()
|
var scalingResourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
var sharpeningResourceLayout = new ResourceLayoutBuilder()
|
var sharpeningResourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 3)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 3)
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 4)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 4)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
_sampler = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
_sampler = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||||||
var resourceLayout = new ResourceLayoutBuilder()
|
var resourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
_samplerLinear = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
_samplerLinear = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
||||||
|
|
||||||
|
@ -81,20 +81,20 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||||||
var edgeResourceLayout = new ResourceLayoutBuilder()
|
var edgeResourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
var blendResourceLayout = new ResourceLayoutBuilder()
|
var blendResourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 3)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 3)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 4)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 4)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
var neighbourResourceLayout = new ResourceLayoutBuilder()
|
var neighbourResourceLayout = new ResourceLayoutBuilder()
|
||||||
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
.Add(ResourceStages.Compute, ResourceType.UniformBuffer, 2)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 1)
|
||||||
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 3)
|
.Add(ResourceStages.Compute, ResourceType.TextureAndSampler, 3)
|
||||||
.Add(ResourceStages.Compute, ResourceType.Image, 0).Build();
|
.Add(ResourceStages.Compute, ResourceType.Image, 0, true).Build();
|
||||||
|
|
||||||
_samplerLinear = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
_samplerLinear = _renderer.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
|
||||||
|
|
||||||
|
@ -10,12 +10,15 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
private readonly Device _device;
|
private readonly Device _device;
|
||||||
private Fence _fence;
|
private Fence _fence;
|
||||||
private int _referenceCount;
|
private int _referenceCount;
|
||||||
|
private int _lock;
|
||||||
|
private readonly bool _concurrentWaitUnsupported;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
public unsafe FenceHolder(Vk api, Device device)
|
public unsafe FenceHolder(Vk api, Device device, bool concurrentWaitUnsupported)
|
||||||
{
|
{
|
||||||
_api = api;
|
_api = api;
|
||||||
_device = device;
|
_device = device;
|
||||||
|
_concurrentWaitUnsupported = concurrentWaitUnsupported;
|
||||||
|
|
||||||
var fenceCreateInfo = new FenceCreateInfo
|
var fenceCreateInfo = new FenceCreateInfo
|
||||||
{
|
{
|
||||||
@ -47,6 +50,11 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
while (Interlocked.CompareExchange(ref _referenceCount, lastValue + 1, lastValue) != lastValue);
|
while (Interlocked.CompareExchange(ref _referenceCount, lastValue + 1, lastValue) != lastValue);
|
||||||
|
|
||||||
|
if (_concurrentWaitUnsupported)
|
||||||
|
{
|
||||||
|
AcquireLock();
|
||||||
|
}
|
||||||
|
|
||||||
fence = _fence;
|
fence = _fence;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -57,6 +65,16 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
return _fence;
|
return _fence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PutLock()
|
||||||
|
{
|
||||||
|
Put();
|
||||||
|
|
||||||
|
if (_concurrentWaitUnsupported)
|
||||||
|
{
|
||||||
|
ReleaseLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Put()
|
public void Put()
|
||||||
{
|
{
|
||||||
if (Interlocked.Decrement(ref _referenceCount) == 0)
|
if (Interlocked.Decrement(ref _referenceCount) == 0)
|
||||||
@ -66,24 +84,67 @@ namespace Ryujinx.Graphics.Vulkan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AcquireLock()
|
||||||
|
{
|
||||||
|
while (!TryAcquireLock())
|
||||||
|
{
|
||||||
|
Thread.SpinWait(32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryAcquireLock()
|
||||||
|
{
|
||||||
|
return Interlocked.Exchange(ref _lock, 1) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReleaseLock()
|
||||||
|
{
|
||||||
|
Interlocked.Exchange(ref _lock, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public void Wait()
|
public void Wait()
|
||||||
{
|
{
|
||||||
Span<Fence> fences = stackalloc Fence[]
|
if (_concurrentWaitUnsupported)
|
||||||
{
|
{
|
||||||
_fence,
|
AcquireLock();
|
||||||
};
|
|
||||||
|
|
||||||
FenceHelper.WaitAllIndefinitely(_api, _device, fences);
|
try
|
||||||
|
{
|
||||||
|
FenceHelper.WaitAllIndefinitely(_api, _device, stackalloc Fence[] { _fence });
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ReleaseLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FenceHelper.WaitAllIndefinitely(_api, _device, stackalloc Fence[] { _fence });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSignaled()
|
public bool IsSignaled()
|
||||||
{
|
{
|
||||||
Span<Fence> fences = stackalloc Fence[]
|
if (_concurrentWaitUnsupported)
|
||||||
{
|
{
|
||||||
_fence,
|
if (!TryAcquireLock())
|
||||||
};
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return FenceHelper.AllSignaled(_api, _device, fences);
|
try
|
||||||
|
{
|
||||||
|
return FenceHelper.AllSignaled(_api, _device, stackalloc Fence[] { _fence });
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ReleaseLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FenceHelper.AllSignaled(_api, _device, stackalloc Fence[] { _fence });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user