2021-06-29 19:32:02 +02:00
|
|
|
using Ryujinx.Graphics.Gpu.Memory;
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
|
|
{
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Sampler pool.
|
|
|
|
/// </summary>
|
2021-01-29 04:19:06 +01:00
|
|
|
class SamplerPool : Pool<Sampler, SamplerDescriptor>
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-11-13 20:04:21 +01:00
|
|
|
private float _forcedAnisotropy;
|
|
|
|
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Constructs a new instance of the sampler pool.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context">GPU context that the sampler pool belongs to</param>
|
2021-06-29 19:32:02 +02:00
|
|
|
/// <param name="physicalMemory">Physical memory where the sampler descriptors are mapped</param>
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <param name="address">Address of the sampler pool in guest memory</param>
|
|
|
|
/// <param name="maximumId">Maximum sampler ID of the sampler pool (equal to maximum samplers minus one)</param>
|
2021-11-13 20:04:21 +01:00
|
|
|
public SamplerPool(GpuContext context, PhysicalMemory physicalMemory, ulong address, int maximumId) : base(context, physicalMemory, address, maximumId)
|
|
|
|
{
|
|
|
|
_forcedAnisotropy = GraphicsConfig.MaxAnisotropy;
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the sampler with the given ID.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">ID of the sampler. This is effectively a zero-based index</param>
|
|
|
|
/// <returns>The sampler with the given ID</returns>
|
2019-10-13 08:02:07 +02:00
|
|
|
public override Sampler Get(int id)
|
|
|
|
{
|
|
|
|
if ((uint)id >= Items.Length)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
Replace CacheResourceWrite with more general "precise" write (#2684)
* Replace CacheResourceWrite with more general "precise" write
The goal of CacheResourceWrite was to notify GPU resources when they were modified directly, by looking up the modified address/size in a structure and calling a method on each resource. The downside of this is that each resource cache has to be queried individually, they all have to implement their own way to do this, and it can only signal to resources using the same PhysicalMemory instance.
This PR adds the ability to signal a write as "precise" on the tracking, which signals a special handler (if present) which can be used to avoid unnecessary flush actions, or maybe even more. For buffers, precise writes specifically do not flush, and instead punch a hole in the modified range list to indicate that the data on GPU has been replaced.
The downside is that precise actions must ignore the page protection bits and always signal - as they need to notify the target resource to ignore the sequence number optimization.
I had to reintroduce the sequence number increment after I2M, as removing it was causing issues in rabbids kingdom battle. However - all resources modified by I2M are notified directly to lower their sequence number, so the problem is likely that another unrelated resource is not being properly updated. Thankfully, doing this does not affect performance in the games I tested.
This should fix regressions from #2624. Test any games that were broken by that. (RF4, rabbids kingdom battle)
I've also added a sequence number increment to ThreedClass.IncrementSyncpoint, as it seems to fix buffer corruption in OpenGL homebrew. (this was a regression from removing sequence number increment from constant buffer update - another unrelated resource thing)
* Add tests.
* Add XML docs for GpuRegionHandle
* Skip UpdateProtection if only precise actions were called
This allows precise actions to skip reprotection costs.
2021-09-29 02:27:03 +02:00
|
|
|
if (SequenceNumber != Context.SequenceNumber)
|
2019-11-23 06:17:22 +01:00
|
|
|
{
|
2021-11-13 20:04:21 +01:00
|
|
|
if (_forcedAnisotropy != GraphicsConfig.MaxAnisotropy)
|
|
|
|
{
|
|
|
|
_forcedAnisotropy = GraphicsConfig.MaxAnisotropy;
|
|
|
|
|
|
|
|
for (int i = 0; i < Items.Length; i++)
|
|
|
|
{
|
|
|
|
if (Items[i] != null)
|
|
|
|
{
|
|
|
|
Items[i].Dispose();
|
|
|
|
|
|
|
|
Items[i] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Replace CacheResourceWrite with more general "precise" write (#2684)
* Replace CacheResourceWrite with more general "precise" write
The goal of CacheResourceWrite was to notify GPU resources when they were modified directly, by looking up the modified address/size in a structure and calling a method on each resource. The downside of this is that each resource cache has to be queried individually, they all have to implement their own way to do this, and it can only signal to resources using the same PhysicalMemory instance.
This PR adds the ability to signal a write as "precise" on the tracking, which signals a special handler (if present) which can be used to avoid unnecessary flush actions, or maybe even more. For buffers, precise writes specifically do not flush, and instead punch a hole in the modified range list to indicate that the data on GPU has been replaced.
The downside is that precise actions must ignore the page protection bits and always signal - as they need to notify the target resource to ignore the sequence number optimization.
I had to reintroduce the sequence number increment after I2M, as removing it was causing issues in rabbids kingdom battle. However - all resources modified by I2M are notified directly to lower their sequence number, so the problem is likely that another unrelated resource is not being properly updated. Thankfully, doing this does not affect performance in the games I tested.
This should fix regressions from #2624. Test any games that were broken by that. (RF4, rabbids kingdom battle)
I've also added a sequence number increment to ThreedClass.IncrementSyncpoint, as it seems to fix buffer corruption in OpenGL homebrew. (this was a regression from removing sequence number increment from constant buffer update - another unrelated resource thing)
* Add tests.
* Add XML docs for GpuRegionHandle
* Skip UpdateProtection if only precise actions were called
This allows precise actions to skip reprotection costs.
2021-09-29 02:27:03 +02:00
|
|
|
SequenceNumber = Context.SequenceNumber;
|
2019-11-23 06:17:22 +01:00
|
|
|
|
|
|
|
SynchronizeMemory();
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
|
|
|
|
Sampler sampler = Items[id];
|
|
|
|
|
|
|
|
if (sampler == null)
|
|
|
|
{
|
2021-01-29 04:19:06 +01:00
|
|
|
SamplerDescriptor descriptor = GetDescriptor(id);
|
2019-10-13 08:02:07 +02:00
|
|
|
|
|
|
|
sampler = new Sampler(Context, descriptor);
|
|
|
|
|
|
|
|
Items[id] = sampler;
|
2021-01-29 04:19:06 +01:00
|
|
|
|
|
|
|
DescriptorCache[id] = descriptor;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return sampler;
|
|
|
|
}
|
|
|
|
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Implementation of the sampler pool range invalidation.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address">Start address of the range of the sampler pool</param>
|
|
|
|
/// <param name="size">Size of the range being invalidated</param>
|
2019-10-13 08:02:07 +02:00
|
|
|
protected override void InvalidateRangeImpl(ulong address, ulong size)
|
|
|
|
{
|
|
|
|
ulong endAddress = address + size;
|
|
|
|
|
|
|
|
for (; address < endAddress; address += DescriptorSize)
|
|
|
|
{
|
|
|
|
int id = (int)((address - Address) / DescriptorSize);
|
|
|
|
|
|
|
|
Sampler sampler = Items[id];
|
|
|
|
|
|
|
|
if (sampler != null)
|
|
|
|
{
|
2021-01-29 04:19:06 +01:00
|
|
|
SamplerDescriptor descriptor = GetDescriptor(id);
|
|
|
|
|
|
|
|
// If the descriptors are the same, the sampler is still valid.
|
|
|
|
if (descriptor.Equals(ref DescriptorCache[id]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
sampler.Dispose();
|
|
|
|
|
|
|
|
Items[id] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-30 00:26:37 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Deletes a given sampler pool entry.
|
|
|
|
/// The host memory used by the sampler is released by the driver.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The entry to be deleted</param>
|
2019-10-13 08:02:07 +02:00
|
|
|
protected override void Delete(Sampler item)
|
|
|
|
{
|
|
|
|
item?.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|