GPU: Pass SpanOrArray for Texture SetData to avoid copy (#3745)
* GPU: Pass SpanOrArray for Texture SetData to avoid copy
Texture data is often converted before upload, meaning that an array was allocated to perform the conversion into. However, the backend SetData methods were being passed a Span of that data, and the Multithreaded layer does `ToArray()` on it so that it can be stored for later! This method can't extract the original array, so it creates a copy.
This PR changes the type passed for textures to a new ref struct called SpanOrArray, which is backed by either a ReadOnlySpan or an array. The benefit here is that we can have a ToArray method that doesn't copy if it is originally backed by an array.
This will also avoid a copy when running the ASTC decoder.
On NieR this was taking 38% of texture upload time, which it does a _lot_ of when you move between areas, so there should be a 1.6x performance boost when strictly uploading textures. No doubt this will also improve texture streaming performance in UE4 games, and maybe a small reduction with video playback.
From the numbers, it's probably possible to improve the upload rate by a further 1.6x by performing layout conversion on GPU. I'm not sure if we could improve it further than that - multithreading conversion on CPU would probably result in memory bottleneck.
This doesn't extend to buffers, since we don't convert their data on the GPU emulator side.
* Remove implicit cast to array.
2022-10-08 11:04:47 -04:00
|
|
|
|
using Ryujinx.Common.Memory;
|
|
|
|
|
using Ryujinx.Cpu.Tracking;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Memory;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
using Ryujinx.Graphics.Texture;
|
2022-01-09 11:28:48 -05:00
|
|
|
|
using Ryujinx.Memory;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
using Ryujinx.Memory.Range;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-01-09 11:28:48 -05:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An overlapping texture group with a given view compatibility.
|
|
|
|
|
/// </summary>
|
2022-12-05 08:47:39 -05:00
|
|
|
|
readonly struct TextureIncompatibleOverlap
|
2022-01-09 11:28:48 -05:00
|
|
|
|
{
|
|
|
|
|
public readonly TextureGroup Group;
|
|
|
|
|
public readonly TextureViewCompatibility Compatibility;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new texture incompatible overlap.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="group">The group that is incompatible</param>
|
|
|
|
|
/// <param name="compatibility">The view compatibility for the group</param>
|
|
|
|
|
public TextureIncompatibleOverlap(TextureGroup group, TextureViewCompatibility compatibility)
|
|
|
|
|
{
|
|
|
|
|
Group = group;
|
|
|
|
|
Compatibility = compatibility;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A texture group represents a group of textures that belong to the same storage.
|
|
|
|
|
/// When views are created, this class will track memory accesses for them separately.
|
|
|
|
|
/// The group iteratively adds more granular tracking as views of different kinds are added.
|
|
|
|
|
/// Note that a texture group can be absorbed into another when it becomes a view parent.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class TextureGroup : IDisposable
|
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Threshold of layers to force granular handles (and thus partial loading) on array/3D textures.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int GranularLayerThreshold = 8;
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
private delegate void HandlesCallbackDelegate(int baseHandle, int regionCount, bool split = false);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The storage texture associated with this group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Texture Storage { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the texture has copy dependencies. If true, then all modifications
|
|
|
|
|
/// must be signalled to the group, rather than skipping ones still to be flushed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasCopyDependencies { get; set; }
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if this texture has any incompatible overlaps alive.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasIncompatibleOverlaps => _incompatibleOverlaps.Count > 0;
|
|
|
|
|
|
2021-06-29 13:32:02 -04:00
|
|
|
|
private readonly GpuContext _context;
|
|
|
|
|
private readonly PhysicalMemory _physicalMemory;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
private int[] _allOffsets;
|
|
|
|
|
private int[] _sliceSizes;
|
|
|
|
|
private bool _is3D;
|
|
|
|
|
private bool _hasMipViews;
|
|
|
|
|
private bool _hasLayerViews;
|
|
|
|
|
private int _layers;
|
|
|
|
|
private int _levels;
|
|
|
|
|
|
|
|
|
|
private MultiRange TextureRange => Storage.Range;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The views list from the storage texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<Texture> _views;
|
|
|
|
|
private TextureGroupHandle[] _handles;
|
|
|
|
|
private bool[] _loadNeeded;
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Other texture groups that have incompatible overlaps with this one.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<TextureIncompatibleOverlap> _incompatibleOverlaps;
|
|
|
|
|
private bool _incompatibleOverlapsDirty = true;
|
|
|
|
|
private bool _flushIncompatibleOverlaps;
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new texture group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="context">GPU context that the texture group belongs to</param>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
/// <param name="physicalMemory">Physical memory where the <paramref name="storage"/> texture is mapped</param>
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <param name="storage">The storage texture for this group</param>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <param name="incompatibleOverlaps">Groups that overlap with this one but are incompatible</param>
|
|
|
|
|
public TextureGroup(GpuContext context, PhysicalMemory physicalMemory, Texture storage, List<TextureIncompatibleOverlap> incompatibleOverlaps)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
Storage = storage;
|
|
|
|
|
_context = context;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
_physicalMemory = physicalMemory;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
_is3D = storage.Info.Target == Target.Texture3D;
|
|
|
|
|
_layers = storage.Info.GetSlices();
|
|
|
|
|
_levels = storage.Info.Levels;
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
|
|
|
|
_incompatibleOverlaps = incompatibleOverlaps;
|
|
|
|
|
_flushIncompatibleOverlaps = TextureCompatibility.IsFormatHostIncompatible(storage.Info, context.Capabilities);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize a new texture group's dirty regions and offsets.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="size">Size info for the storage texture</param>
|
|
|
|
|
/// <param name="hasLayerViews">True if the storage will have layer views</param>
|
|
|
|
|
/// <param name="hasMipViews">True if the storage will have mip views</param>
|
|
|
|
|
public void Initialize(ref SizeInfo size, bool hasLayerViews, bool hasMipViews)
|
|
|
|
|
{
|
|
|
|
|
_allOffsets = size.AllOffsets;
|
|
|
|
|
_sliceSizes = size.SliceSizes;
|
|
|
|
|
|
2023-03-14 16:08:44 -04:00
|
|
|
|
if (Storage.Target.HasDepthOrLayers() && Storage.Info.GetSlices() > GranularLayerThreshold)
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = true;
|
|
|
|
|
_hasMipViews = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(_hasLayerViews, _hasMipViews) = PropagateGranularity(hasLayerViews, hasMipViews);
|
|
|
|
|
|
|
|
|
|
// If the texture is partially mapped, fully subdivide handles immediately.
|
|
|
|
|
|
|
|
|
|
MultiRange range = Storage.Range;
|
|
|
|
|
for (int i = 0; i < range.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (range.GetSubRange(i).Address == MemoryManager.PteUnmapped)
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = true;
|
|
|
|
|
_hasMipViews = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
RecalculateHandleRegions();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize all incompatible overlaps in the list, registering them with the other texture groups
|
|
|
|
|
/// and creating copy dependencies when partially compatible.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitializeOverlaps()
|
|
|
|
|
{
|
|
|
|
|
foreach (TextureIncompatibleOverlap overlap in _incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
if (overlap.Compatibility == TextureViewCompatibility.LayoutIncompatible)
|
|
|
|
|
{
|
|
|
|
|
CreateCopyDependency(overlap.Group, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
overlap.Group._incompatibleOverlaps.Add(new TextureIncompatibleOverlap(this, overlap.Compatibility));
|
|
|
|
|
overlap.Group._incompatibleOverlapsDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_incompatibleOverlaps.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
SignalIncompatibleOverlapModified();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Signal that the group is dirty to all views and the storage.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SignalAllDirty()
|
|
|
|
|
{
|
|
|
|
|
Storage.SignalGroupDirty();
|
|
|
|
|
if (_views != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture texture in _views)
|
|
|
|
|
{
|
|
|
|
|
texture.SignalGroupDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Signal that an incompatible overlap has been modified.
|
|
|
|
|
/// If this group must flush incompatible overlaps, the group is signalled as dirty too.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SignalIncompatibleOverlapModified()
|
|
|
|
|
{
|
|
|
|
|
_incompatibleOverlapsDirty = true;
|
|
|
|
|
|
|
|
|
|
if (_flushIncompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
SignalAllDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flushes incompatible overlaps if the storage format requires it, and they have been modified.
|
|
|
|
|
/// This allows unsupported host formats to accept data written to format aliased textures.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if data was flushed, false otherwise</returns>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public bool FlushIncompatibleOverlapsIfNeeded()
|
|
|
|
|
{
|
|
|
|
|
if (_flushIncompatibleOverlaps && _incompatibleOverlapsDirty)
|
|
|
|
|
{
|
|
|
|
|
bool flushed = false;
|
|
|
|
|
|
|
|
|
|
foreach (var overlap in _incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
flushed |= overlap.Group.Storage.FlushModified(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_incompatibleOverlapsDirty = false;
|
|
|
|
|
|
|
|
|
|
return flushed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <summary>
|
2021-08-20 16:52:09 -04:00
|
|
|
|
/// Check and optionally consume the dirty flags for a given texture.
|
|
|
|
|
/// The state is shared between views of the same layers and levels.
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture being used</param>
|
2021-08-20 16:52:09 -04:00
|
|
|
|
/// <param name="consume">True to consume the dirty flags and reprotect, false to leave them as is</param>
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <returns>True if a flag was dirty, false otherwise</returns>
|
2021-08-20 16:52:09 -04:00
|
|
|
|
public bool CheckDirty(Texture texture, bool consume)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
bool dirty = false;
|
|
|
|
|
|
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
|
|
|
|
foreach (CpuRegionHandle handle in group.Handles)
|
|
|
|
|
{
|
|
|
|
|
if (handle.Dirty)
|
|
|
|
|
{
|
2021-08-20 16:52:09 -04:00
|
|
|
|
if (consume)
|
|
|
|
|
{
|
|
|
|
|
handle.Reprotect();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
dirty = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-02-22 11:34:16 -05:00
|
|
|
|
/// Synchronize memory for a given texture.
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// If overlapping tracking handles are dirty, fully or partially synchronize the texture data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture being used</param>
|
|
|
|
|
public void SynchronizeMemory(Texture texture)
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
FlushIncompatibleOverlapsIfNeeded();
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
|
|
|
|
bool dirty = false;
|
|
|
|
|
bool anyModified = false;
|
2023-03-14 16:08:44 -04:00
|
|
|
|
bool anyNotDirty = false;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
|
|
|
|
bool modified = group.Modified;
|
|
|
|
|
bool handleDirty = false;
|
2021-03-06 09:43:55 -05:00
|
|
|
|
bool handleUnmapped = false;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
foreach (CpuRegionHandle handle in group.Handles)
|
|
|
|
|
{
|
|
|
|
|
if (handle.Dirty)
|
|
|
|
|
{
|
|
|
|
|
handle.Reprotect();
|
|
|
|
|
handleDirty = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-06 09:43:55 -05:00
|
|
|
|
handleUnmapped |= handle.Unmapped;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
// If the modified flag is still present, prefer the data written from gpu.
|
|
|
|
|
// A write from CPU will do a flush before writing its data, which should unset this.
|
|
|
|
|
if (modified)
|
|
|
|
|
{
|
|
|
|
|
handleDirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
// Evaluate if any copy dependencies need to be fulfilled. A few rules:
|
|
|
|
|
// If the copy handle needs to be synchronized, prefer our own state.
|
2022-02-22 11:34:16 -05:00
|
|
|
|
// If we need to be synchronized and there is a copy present, prefer the copy.
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
if (group.NeedsCopy && group.Copy(_context))
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
anyModified |= true; // The copy target has been modified.
|
|
|
|
|
handleDirty = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
anyModified |= modified;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
dirty |= handleDirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (group.NeedsCopy)
|
|
|
|
|
{
|
|
|
|
|
// The texture we copied from is still being written to. Copy from it again the next time this texture is used.
|
|
|
|
|
texture.SignalGroupDirty();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:08:44 -04:00
|
|
|
|
bool loadNeeded = handleDirty && !handleUnmapped;
|
|
|
|
|
|
|
|
|
|
anyNotDirty |= !loadNeeded;
|
|
|
|
|
_loadNeeded[baseHandle + i] = loadNeeded;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
if (anyNotDirty || (_handles.Length > 1 && (anyModified || split)))
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
// Partial texture invalidation. Only update the layers/levels with dirty flags of the storage.
|
|
|
|
|
|
|
|
|
|
SynchronizePartial(baseHandle, regionCount);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Full texture invalidation.
|
|
|
|
|
|
|
|
|
|
texture.SynchronizeFull();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Synchronize part of the storage texture, represented by a given range of handles.
|
|
|
|
|
/// Only handles marked by the _loadNeeded array will be synchronized.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="baseHandle">The base index of the range of handles</param>
|
|
|
|
|
/// <param name="regionCount">The number of handles to synchronize</param>
|
|
|
|
|
private void SynchronizePartial(int baseHandle, int regionCount)
|
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
int spanEndIndex = -1;
|
|
|
|
|
int spanBase = 0;
|
|
|
|
|
ReadOnlySpan<byte> dataSpan = ReadOnlySpan<byte>.Empty;
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (_loadNeeded[baseHandle + i])
|
|
|
|
|
{
|
|
|
|
|
var info = GetHandleInformation(baseHandle + i);
|
|
|
|
|
|
2023-03-14 16:08:44 -04:00
|
|
|
|
// Ensure the data for this handle is loaded in the span.
|
|
|
|
|
if (spanEndIndex <= i - 1)
|
|
|
|
|
{
|
|
|
|
|
spanEndIndex = i;
|
|
|
|
|
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
// Look ahead to see how many handles need to be loaded.
|
|
|
|
|
for (int j = i + 1; j < regionCount; j++)
|
|
|
|
|
{
|
|
|
|
|
if (_loadNeeded[baseHandle + j])
|
|
|
|
|
{
|
|
|
|
|
spanEndIndex = j;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var endInfo = spanEndIndex == i ? info : GetHandleInformation(baseHandle + spanEndIndex);
|
|
|
|
|
|
|
|
|
|
spanBase = _allOffsets[info.Index];
|
|
|
|
|
int spanLast = _allOffsets[endInfo.Index + endInfo.Layers * endInfo.Levels - 1];
|
|
|
|
|
int endOffset = Math.Min(spanLast + _sliceSizes[endInfo.BaseLevel + endInfo.Levels - 1], (int)Storage.Size);
|
|
|
|
|
int size = endOffset - spanBase;
|
|
|
|
|
|
|
|
|
|
dataSpan = _physicalMemory.GetSpan(Storage.Range.GetSlice((ulong)spanBase, (ulong)size));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
// Only one of these will be greater than 1, as partial sync is only called when there are sub-image views.
|
|
|
|
|
for (int layer = 0; layer < info.Layers; layer++)
|
|
|
|
|
{
|
|
|
|
|
for (int level = 0; level < info.Levels; level++)
|
|
|
|
|
{
|
2023-02-12 04:30:26 -05:00
|
|
|
|
int offsetIndex = GetOffsetIndex(info.BaseLayer + layer, info.BaseLevel + level);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
int offset = _allOffsets[offsetIndex];
|
|
|
|
|
|
2023-03-14 16:08:44 -04:00
|
|
|
|
ReadOnlySpan<byte> data = dataSpan.Slice(offset - spanBase);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2023-02-12 04:30:26 -05:00
|
|
|
|
SpanOrArray<byte> result = Storage.ConvertToHostCompatibleFormat(data, info.BaseLevel + level, true);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2023-02-12 04:30:26 -05:00
|
|
|
|
Storage.SetData(result, info.BaseLayer + layer, info.BaseLevel + level);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 20:11:05 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Synchronize dependent textures, if any of them have deferred a copy from the given texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture to synchronize dependents of</param>
|
|
|
|
|
public void SynchronizeDependents(Texture texture)
|
|
|
|
|
{
|
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
|
|
|
|
group.SynchronizeDependents();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <summary>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// Determines whether flushes in this texture group should be tracked.
|
|
|
|
|
/// Incompatible overlaps may need data from this texture to flush tracked for it to be visible to them.
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// </summary>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <returns>True if flushes should be tracked, false otherwise</returns>
|
|
|
|
|
private bool ShouldFlushTriggerTracking()
|
|
|
|
|
{
|
|
|
|
|
foreach (var overlap in _incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
if (overlap.Group._flushIncompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets data from the host GPU, and flushes a slice to guest memory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method should be used to retrieve data that was modified by the host GPU.
|
|
|
|
|
/// This is not cheap, avoid doing that unless strictly needed.
|
|
|
|
|
/// When possible, the data is written directly into guest memory, rather than copied.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="tracked">True if writing the texture data is tracked, false otherwise</param>
|
|
|
|
|
/// <param name="sliceIndex">The index of the slice to flush</param>
|
|
|
|
|
/// <param name="texture">The specific host texture to flush. Defaults to the storage texture</param>
|
|
|
|
|
private void FlushTextureDataSliceToGuest(bool tracked, int sliceIndex, ITexture texture = null)
|
|
|
|
|
{
|
|
|
|
|
(int layer, int level) = GetLayerLevelForView(sliceIndex);
|
|
|
|
|
|
|
|
|
|
int offset = _allOffsets[sliceIndex];
|
|
|
|
|
int endOffset = Math.Min(offset + _sliceSizes[level], (int)Storage.Size);
|
|
|
|
|
int size = endOffset - offset;
|
|
|
|
|
|
|
|
|
|
using WritableRegion region = _physicalMemory.GetWritableRegion(Storage.Range.GetSlice((ulong)offset, (ulong)size), tracked);
|
|
|
|
|
|
|
|
|
|
Storage.GetTextureDataSliceFromGpu(region.Memory.Span, layer, level, tracked, texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets and flushes a number of slices of the storage texture to guest memory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tracked">True if writing the texture data is tracked, false otherwise</param>
|
|
|
|
|
/// <param name="sliceStart">The first slice to flush</param>
|
|
|
|
|
/// <param name="sliceEnd">The slice to finish flushing on (exclusive)</param>
|
|
|
|
|
/// <param name="texture">The specific host texture to flush. Defaults to the storage texture</param>
|
|
|
|
|
private void FlushSliceRange(bool tracked, int sliceStart, int sliceEnd, ITexture texture = null)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
for (int i = sliceStart; i < sliceEnd; i++)
|
|
|
|
|
{
|
|
|
|
|
FlushTextureDataSliceToGuest(tracked, i, texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flush modified ranges for a given texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture being used</param>
|
|
|
|
|
/// <param name="tracked">True if the flush writes should be tracked, false otherwise</param>
|
|
|
|
|
/// <returns>True if data was flushed, false otherwise</returns>
|
|
|
|
|
public bool FlushModified(Texture texture, bool tracked)
|
|
|
|
|
{
|
|
|
|
|
tracked = tracked || ShouldFlushTriggerTracking();
|
|
|
|
|
bool flushed = false;
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
int startSlice = 0;
|
|
|
|
|
int endSlice = 0;
|
|
|
|
|
bool allModified = true;
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
if (group.Modified)
|
|
|
|
|
{
|
|
|
|
|
if (endSlice < group.BaseSlice)
|
|
|
|
|
{
|
|
|
|
|
if (endSlice > startSlice)
|
|
|
|
|
{
|
|
|
|
|
FlushSliceRange(tracked, startSlice, endSlice);
|
|
|
|
|
flushed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startSlice = group.BaseSlice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endSlice = group.BaseSlice + group.SliceCount;
|
|
|
|
|
|
|
|
|
|
if (tracked)
|
|
|
|
|
{
|
|
|
|
|
group.Modified = false;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
foreach (Texture texture in group.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
texture.SignalModifiedDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
allModified = false;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
|
|
|
|
if (endSlice > startSlice)
|
|
|
|
|
{
|
|
|
|
|
if (allModified && !split)
|
|
|
|
|
{
|
|
|
|
|
texture.Flush(tracked);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlushSliceRange(tracked, startSlice, endSlice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flushed = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Storage.SignalModifiedDirty();
|
|
|
|
|
|
|
|
|
|
return flushed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clears competing modified flags for all incompatible ranges, if they have possibly been modified.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture that has been modified</param>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void ClearIncompatibleOverlaps(Texture texture)
|
|
|
|
|
{
|
|
|
|
|
if (_incompatibleOverlapsDirty)
|
|
|
|
|
{
|
|
|
|
|
foreach (TextureIncompatibleOverlap incompatible in _incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
incompatible.Group.ClearModified(texture.Range, this);
|
|
|
|
|
|
|
|
|
|
incompatible.Group.SignalIncompatibleOverlapModified();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_incompatibleOverlapsDirty = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Signal that a texture in the group has been modified by the GPU.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture that has been modified</param>
|
|
|
|
|
public void SignalModified(Texture texture)
|
|
|
|
|
{
|
|
|
|
|
ClearIncompatibleOverlaps(texture);
|
|
|
|
|
|
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
|
|
|
|
group.SignalModified(_context);
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Signal that a texture in the group is actively bound, or has been unbound by the GPU.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture that has been modified</param>
|
|
|
|
|
/// <param name="bound">True if this texture is being bound, false if unbound</param>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
public void SignalModifying(Texture texture, bool bound)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
ClearIncompatibleOverlaps(texture);
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < regionCount; i++)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle group = _handles[baseHandle + i];
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
group.SignalModifying(bound, _context);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Register a read/write action to flush for a texture group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="group">The group to register an action for</param>
|
|
|
|
|
public void RegisterAction(TextureGroupHandle group)
|
|
|
|
|
{
|
|
|
|
|
foreach (CpuRegionHandle handle in group.Handles)
|
|
|
|
|
{
|
|
|
|
|
handle.RegisterAction((address, size) => FlushAction(group, address, size));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Propagates the mip/layer view flags depending on the texture type.
|
|
|
|
|
/// When the most granular type of subresource has views, the other type of subresource must be segmented granularly too.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hasLayerViews">True if the storage has layer views</param>
|
|
|
|
|
/// <param name="hasMipViews">True if the storage has mip views</param>
|
|
|
|
|
/// <returns>The input values after propagation</returns>
|
|
|
|
|
private (bool HasLayerViews, bool HasMipViews) PropagateGranularity(bool hasLayerViews, bool hasMipViews)
|
|
|
|
|
{
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
hasMipViews |= hasLayerViews;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hasLayerViews |= hasMipViews;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (hasLayerViews, hasMipViews);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Evaluate the range of tracking handles which a view texture overlaps with.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture to get handles for</param>
|
|
|
|
|
/// <param name="callback">
|
|
|
|
|
/// A function to be called with the base index of the range of handles for the given texture, and the number of handles it covers.
|
|
|
|
|
/// This can be called for multiple disjoint ranges, if required.
|
|
|
|
|
/// </param>
|
|
|
|
|
private void EvaluateRelevantHandles(Texture texture, HandlesCallbackDelegate callback)
|
|
|
|
|
{
|
|
|
|
|
if (texture == Storage || !(_hasMipViews || _hasLayerViews))
|
|
|
|
|
{
|
|
|
|
|
callback(0, _handles.Length);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EvaluateRelevantHandles(texture.FirstLayer, texture.FirstLevel, texture.Info.GetSlices(), texture.Info.Levels, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-02-22 11:34:16 -05:00
|
|
|
|
/// Evaluate the range of tracking handles which a view texture overlaps with,
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// using the view's position and slice/level counts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="firstLayer">The first layer of the texture</param>
|
|
|
|
|
/// <param name="firstLevel">The first level of the texture</param>
|
|
|
|
|
/// <param name="slices">The slice count of the texture</param>
|
|
|
|
|
/// <param name="levels">The level count of the texture</param>
|
|
|
|
|
/// <param name="callback">
|
|
|
|
|
/// A function to be called with the base index of the range of handles for the given texture, and the number of handles it covers.
|
|
|
|
|
/// This can be called for multiple disjoint ranges, if required.
|
|
|
|
|
/// </param>
|
|
|
|
|
private void EvaluateRelevantHandles(int firstLayer, int firstLevel, int slices, int levels, HandlesCallbackDelegate callback)
|
|
|
|
|
{
|
|
|
|
|
int targetLayerHandles = _hasLayerViews ? slices : 1;
|
|
|
|
|
int targetLevelHandles = _hasMipViews ? levels : 1;
|
|
|
|
|
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
// Future mip levels come after all layers of the last mip level. Each mipmap has less layers (depth) than the last.
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
if (!_hasLayerViews)
|
|
|
|
|
{
|
|
|
|
|
// When there are no layer views, the mips are at a consistent offset.
|
|
|
|
|
|
|
|
|
|
callback(firstLevel, targetLevelHandles);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(int levelIndex, int layerCount) = Get3DLevelRange(firstLevel);
|
|
|
|
|
|
|
|
|
|
if (levels > 1 && slices < _layers)
|
|
|
|
|
{
|
|
|
|
|
// The given texture only covers some of the depth of multiple mips. (a "depth slice")
|
|
|
|
|
// Callback with each mip's range separately.
|
|
|
|
|
// Can assume that the group is fully subdivided (both slices and levels > 1 for storage)
|
|
|
|
|
|
|
|
|
|
while (levels-- > 1)
|
|
|
|
|
{
|
|
|
|
|
callback(firstLayer + levelIndex, slices);
|
|
|
|
|
|
|
|
|
|
levelIndex += layerCount;
|
|
|
|
|
layerCount = Math.Max(layerCount >> 1, 1);
|
|
|
|
|
slices = Math.Max(layerCount >> 1, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int totalSize = Math.Min(layerCount, slices);
|
|
|
|
|
|
|
|
|
|
while (levels-- > 1)
|
|
|
|
|
{
|
|
|
|
|
layerCount = Math.Max(layerCount >> 1, 1);
|
|
|
|
|
totalSize += layerCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(firstLayer + levelIndex, totalSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Future layers come after all mipmaps of the last.
|
|
|
|
|
int levelHandles = _hasMipViews ? _levels : 1;
|
|
|
|
|
|
|
|
|
|
if (slices > 1 && levels < _levels)
|
|
|
|
|
{
|
|
|
|
|
// The given texture only covers some of the mipmaps of multiple slices. (a "mip slice")
|
|
|
|
|
// Callback with each layer's range separately.
|
|
|
|
|
// Can assume that the group is fully subdivided (both slices and levels > 1 for storage)
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < slices; i++)
|
|
|
|
|
{
|
|
|
|
|
callback(firstLevel + (firstLayer + i) * levelHandles, targetLevelHandles, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
callback(firstLevel + firstLayer * levelHandles, targetLevelHandles + (targetLayerHandles - 1) * levelHandles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the range of offsets for a given mip level of a 3D texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="level">The level to return</param>
|
|
|
|
|
/// <returns>Start index and count of offsets for the given level</returns>
|
|
|
|
|
private (int Index, int Count) Get3DLevelRange(int level)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
int count = _layers; // Depth. Halves with each mip level.
|
|
|
|
|
|
|
|
|
|
while (level-- > 0)
|
|
|
|
|
{
|
|
|
|
|
index += count;
|
|
|
|
|
count = Math.Max(count >> 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (index, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get view information for a single tracking handle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="handleIndex">The index of the handle</param>
|
|
|
|
|
/// <returns>The layers and levels that the handle covers, and its index in the offsets array</returns>
|
|
|
|
|
private (int BaseLayer, int BaseLevel, int Levels, int Layers, int Index) GetHandleInformation(int handleIndex)
|
|
|
|
|
{
|
|
|
|
|
int baseLayer;
|
|
|
|
|
int baseLevel;
|
|
|
|
|
int levels = _hasMipViews ? 1 : _levels;
|
|
|
|
|
int layers = _hasLayerViews ? 1 : _layers;
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
if (_hasLayerViews)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: Will also have mip views, or only one level in storage.
|
|
|
|
|
|
|
|
|
|
index = handleIndex;
|
|
|
|
|
baseLevel = 0;
|
|
|
|
|
|
2021-08-20 13:59:39 -04:00
|
|
|
|
int levelLayers = _layers;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2021-08-20 13:59:39 -04:00
|
|
|
|
while (handleIndex >= levelLayers)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2021-08-20 13:59:39 -04:00
|
|
|
|
handleIndex -= levelLayers;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
baseLevel++;
|
2021-08-20 13:59:39 -04:00
|
|
|
|
levelLayers = Math.Max(levelLayers >> 1, 1);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
baseLayer = handleIndex;
|
2022-01-09 11:28:48 -05:00
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
baseLayer = 0;
|
|
|
|
|
baseLevel = handleIndex;
|
|
|
|
|
|
|
|
|
|
(index, _) = Get3DLevelRange(baseLevel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
baseLevel = _hasMipViews ? handleIndex % _levels : 0;
|
|
|
|
|
baseLayer = _hasMipViews ? handleIndex / _levels : handleIndex;
|
|
|
|
|
index = baseLevel + baseLayer * _levels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (baseLayer, baseLevel, levels, layers, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the layer and level for a given view.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The index of the view</param>
|
|
|
|
|
/// <returns>The layer and level of the specified view</returns>
|
|
|
|
|
private (int BaseLayer, int BaseLevel) GetLayerLevelForView(int index)
|
|
|
|
|
{
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
int baseLevel = 0;
|
|
|
|
|
|
2021-08-20 13:59:39 -04:00
|
|
|
|
int levelLayers = _layers;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2021-08-20 13:59:39 -04:00
|
|
|
|
while (index >= levelLayers)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2021-08-20 13:59:39 -04:00
|
|
|
|
index -= levelLayers;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
baseLevel++;
|
2021-08-20 13:59:39 -04:00
|
|
|
|
levelLayers = Math.Max(levelLayers >> 1, 1);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (index, baseLevel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (index / _levels, index % _levels);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find the byte offset of a given texture relative to the storage.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture to locate</param>
|
|
|
|
|
/// <returns>The offset of the texture in bytes</returns>
|
|
|
|
|
public int FindOffset(Texture texture)
|
|
|
|
|
{
|
|
|
|
|
return _allOffsets[GetOffsetIndex(texture.FirstLayer, texture.FirstLevel)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find the offset index of a given layer and level.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="layer">The view layer</param>
|
|
|
|
|
/// <param name="level">The view level</param>
|
|
|
|
|
/// <returns>The offset index of the given layer and level</returns>
|
|
|
|
|
public int GetOffsetIndex(int layer, int level)
|
|
|
|
|
{
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
return layer + Get3DLevelRange(level).Index;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return level + layer * _levels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The action to perform when a memory tracking handle is flipped to dirty.
|
|
|
|
|
/// This notifies overlapping textures that the memory needs to be synchronized.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="groupHandle">The handle that a dirty flag was set on</param>
|
|
|
|
|
private void DirtyAction(TextureGroupHandle groupHandle)
|
|
|
|
|
{
|
|
|
|
|
// Notify all textures that belong to this handle.
|
|
|
|
|
|
|
|
|
|
Storage.SignalGroupDirty();
|
|
|
|
|
|
|
|
|
|
lock (groupHandle.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture overlap in groupHandle.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
overlap.SignalGroupDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate a CpuRegionHandle for a given address and size range in CPU VA.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address">The start address of the tracked region</param>
|
|
|
|
|
/// <param name="size">The size of the tracked region</param>
|
|
|
|
|
/// <returns>A CpuRegionHandle covering the given range</returns>
|
|
|
|
|
private CpuRegionHandle GenerateHandle(ulong address, ulong size)
|
|
|
|
|
{
|
2023-02-16 16:28:49 -05:00
|
|
|
|
return _physicalMemory.BeginTracking(address, size, ResourceKind.Texture);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate a TextureGroupHandle covering a specified range of views.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="viewStart">The start view of the handle</param>
|
|
|
|
|
/// <param name="views">The number of views to cover</param>
|
|
|
|
|
/// <returns>A TextureGroupHandle covering the given views</returns>
|
|
|
|
|
private TextureGroupHandle GenerateHandles(int viewStart, int views)
|
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
int viewEnd = viewStart + views - 1;
|
|
|
|
|
(_, int lastLevel) = GetLayerLevelForView(viewEnd);
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
int offset = _allOffsets[viewStart];
|
2023-03-14 16:08:44 -04:00
|
|
|
|
int endOffset = _allOffsets[viewEnd] + _sliceSizes[lastLevel];
|
2021-03-02 17:30:54 -05:00
|
|
|
|
int size = endOffset - offset;
|
|
|
|
|
|
|
|
|
|
var result = new List<CpuRegionHandle>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < TextureRange.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
MemoryRange item = TextureRange.GetSubRange(i);
|
|
|
|
|
int subRangeSize = (int)item.Size;
|
|
|
|
|
|
|
|
|
|
int sliceStart = Math.Clamp(offset, 0, subRangeSize);
|
|
|
|
|
int sliceEnd = Math.Clamp(endOffset, 0, subRangeSize);
|
|
|
|
|
|
2022-02-22 11:34:16 -05:00
|
|
|
|
if (sliceStart != sliceEnd && item.Address != MemoryManager.PteUnmapped)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
result.Add(GenerateHandle(item.Address + (ulong)sliceStart, (ulong)(sliceEnd - sliceStart)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset -= subRangeSize;
|
|
|
|
|
endOffset -= subRangeSize;
|
|
|
|
|
|
|
|
|
|
if (endOffset <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(int firstLayer, int firstLevel) = GetLayerLevelForView(viewStart);
|
|
|
|
|
|
|
|
|
|
if (_hasLayerViews && _hasMipViews)
|
|
|
|
|
{
|
|
|
|
|
size = _sliceSizes[firstLevel];
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
offset = _allOffsets[viewStart];
|
|
|
|
|
ulong maxSize = Storage.Size - (ulong)offset;
|
|
|
|
|
|
|
|
|
|
var groupHandle = new TextureGroupHandle(
|
|
|
|
|
this,
|
|
|
|
|
offset,
|
|
|
|
|
Math.Min(maxSize, (ulong)size),
|
|
|
|
|
_views,
|
|
|
|
|
firstLayer,
|
|
|
|
|
firstLevel,
|
|
|
|
|
viewStart,
|
|
|
|
|
views,
|
|
|
|
|
result.ToArray());
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
foreach (CpuRegionHandle handle in result)
|
|
|
|
|
{
|
|
|
|
|
handle.RegisterDirtyEvent(() => DirtyAction(groupHandle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groupHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the views in this texture group, rebuilding the memory tracking if required.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="views">The views list of the storage texture</param>
|
GPU: Fast path for adding one texture view to a group (#4528)
* GPU: Fast path for adding one texture view to a group
Texture group handles must store a list of their overlapping views, so they can be properly notified when a write is detected, and a few other things relating to texture readback. This is generally created when the group is established, with each handle looping over all views to find its overlaps. This whole process was also done when only a single view was added (and no handles were changed), however...
Sonic Frontiers had a huge cubemap array with 7350 faces (175 cubemaps * 6 faces * 7 levels), so iterating over both handles and existing views added up very fast. Since we are only adding a single view, we only need to _add_ that view to the existing overlaps, rather than recalculate them all.
This greatly improves performance during loading screens and a few seconds into gameplay on the "open zone" sections of Sonic Frontiers. May improve loading times or stutters on some other games.
Note that the current texture cache rules will cause these views to fall out of the cache, as there are more than the hard cap, so the cost will be repaid when reloading the open zone.
I also added some code to properly remove overlaps when texture views are removed, since it seems that was missing.
This can be improved further by only iterating handles that overlap the view (filter by range), but so can a few places in TextureGroup, so better to do all at once. The full generation of overlaps could probably be improved in a similar way.
I recommend testing a few games to make sure nothing breaks.
* Address feedback
2023-03-14 16:33:44 -04:00
|
|
|
|
/// <param name="texture">The texture that has been added, if that is the only change, otherwise null</param>
|
|
|
|
|
public void UpdateViews(List<Texture> views, Texture texture)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
// This is saved to calculate overlapping views for each handle.
|
|
|
|
|
_views = views;
|
|
|
|
|
|
|
|
|
|
bool layerViews = _hasLayerViews;
|
|
|
|
|
bool mipViews = _hasMipViews;
|
|
|
|
|
bool regionsRebuilt = false;
|
|
|
|
|
|
|
|
|
|
if (!(layerViews && mipViews))
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture view in views)
|
|
|
|
|
{
|
|
|
|
|
if (view.Info.GetSlices() < _layers)
|
|
|
|
|
{
|
|
|
|
|
layerViews = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (view.Info.Levels < _levels)
|
|
|
|
|
{
|
|
|
|
|
mipViews = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(layerViews, mipViews) = PropagateGranularity(layerViews, mipViews);
|
|
|
|
|
|
|
|
|
|
if (layerViews != _hasLayerViews || mipViews != _hasMipViews)
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = layerViews;
|
|
|
|
|
_hasMipViews = mipViews;
|
|
|
|
|
|
|
|
|
|
RecalculateHandleRegions();
|
|
|
|
|
regionsRebuilt = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!regionsRebuilt)
|
|
|
|
|
{
|
GPU: Fast path for adding one texture view to a group (#4528)
* GPU: Fast path for adding one texture view to a group
Texture group handles must store a list of their overlapping views, so they can be properly notified when a write is detected, and a few other things relating to texture readback. This is generally created when the group is established, with each handle looping over all views to find its overlaps. This whole process was also done when only a single view was added (and no handles were changed), however...
Sonic Frontiers had a huge cubemap array with 7350 faces (175 cubemaps * 6 faces * 7 levels), so iterating over both handles and existing views added up very fast. Since we are only adding a single view, we only need to _add_ that view to the existing overlaps, rather than recalculate them all.
This greatly improves performance during loading screens and a few seconds into gameplay on the "open zone" sections of Sonic Frontiers. May improve loading times or stutters on some other games.
Note that the current texture cache rules will cause these views to fall out of the cache, as there are more than the hard cap, so the cost will be repaid when reloading the open zone.
I also added some code to properly remove overlaps when texture views are removed, since it seems that was missing.
This can be improved further by only iterating handles that overlap the view (filter by range), but so can a few places in TextureGroup, so better to do all at once. The full generation of overlaps could probably be improved in a similar way.
I recommend testing a few games to make sure nothing breaks.
* Address feedback
2023-03-14 16:33:44 -04:00
|
|
|
|
if (texture != null)
|
|
|
|
|
{
|
|
|
|
|
int offset = FindOffset(texture);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
GPU: Fast path for adding one texture view to a group (#4528)
* GPU: Fast path for adding one texture view to a group
Texture group handles must store a list of their overlapping views, so they can be properly notified when a write is detected, and a few other things relating to texture readback. This is generally created when the group is established, with each handle looping over all views to find its overlaps. This whole process was also done when only a single view was added (and no handles were changed), however...
Sonic Frontiers had a huge cubemap array with 7350 faces (175 cubemaps * 6 faces * 7 levels), so iterating over both handles and existing views added up very fast. Since we are only adding a single view, we only need to _add_ that view to the existing overlaps, rather than recalculate them all.
This greatly improves performance during loading screens and a few seconds into gameplay on the "open zone" sections of Sonic Frontiers. May improve loading times or stutters on some other games.
Note that the current texture cache rules will cause these views to fall out of the cache, as there are more than the hard cap, so the cost will be repaid when reloading the open zone.
I also added some code to properly remove overlaps when texture views are removed, since it seems that was missing.
This can be improved further by only iterating handles that overlap the view (filter by range), but so can a few places in TextureGroup, so better to do all at once. The full generation of overlaps could probably be improved in a similar way.
I recommend testing a few games to make sure nothing breaks.
* Address feedback
2023-03-14 16:33:44 -04:00
|
|
|
|
foreach (TextureGroupHandle handle in _handles)
|
|
|
|
|
{
|
|
|
|
|
handle.AddOverlap(offset, texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
GPU: Fast path for adding one texture view to a group (#4528)
* GPU: Fast path for adding one texture view to a group
Texture group handles must store a list of their overlapping views, so they can be properly notified when a write is detected, and a few other things relating to texture readback. This is generally created when the group is established, with each handle looping over all views to find its overlaps. This whole process was also done when only a single view was added (and no handles were changed), however...
Sonic Frontiers had a huge cubemap array with 7350 faces (175 cubemaps * 6 faces * 7 levels), so iterating over both handles and existing views added up very fast. Since we are only adding a single view, we only need to _add_ that view to the existing overlaps, rather than recalculate them all.
This greatly improves performance during loading screens and a few seconds into gameplay on the "open zone" sections of Sonic Frontiers. May improve loading times or stutters on some other games.
Note that the current texture cache rules will cause these views to fall out of the cache, as there are more than the hard cap, so the cost will be repaid when reloading the open zone.
I also added some code to properly remove overlaps when texture views are removed, since it seems that was missing.
This can be improved further by only iterating handles that overlap the view (filter by range), but so can a few places in TextureGroup, so better to do all at once. The full generation of overlaps could probably be improved in a similar way.
I recommend testing a few games to make sure nothing breaks.
* Address feedback
2023-03-14 16:33:44 -04:00
|
|
|
|
// Must update the overlapping views on all handles, but only if they were not just recreated.
|
|
|
|
|
|
|
|
|
|
foreach (TextureGroupHandle handle in _handles)
|
|
|
|
|
{
|
|
|
|
|
handle.RecalculateOverlaps(this, views);
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
SignalAllDirty();
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
GPU: Fast path for adding one texture view to a group (#4528)
* GPU: Fast path for adding one texture view to a group
Texture group handles must store a list of their overlapping views, so they can be properly notified when a write is detected, and a few other things relating to texture readback. This is generally created when the group is established, with each handle looping over all views to find its overlaps. This whole process was also done when only a single view was added (and no handles were changed), however...
Sonic Frontiers had a huge cubemap array with 7350 faces (175 cubemaps * 6 faces * 7 levels), so iterating over both handles and existing views added up very fast. Since we are only adding a single view, we only need to _add_ that view to the existing overlaps, rather than recalculate them all.
This greatly improves performance during loading screens and a few seconds into gameplay on the "open zone" sections of Sonic Frontiers. May improve loading times or stutters on some other games.
Note that the current texture cache rules will cause these views to fall out of the cache, as there are more than the hard cap, so the cost will be repaid when reloading the open zone.
I also added some code to properly remove overlaps when texture views are removed, since it seems that was missing.
This can be improved further by only iterating handles that overlap the view (filter by range), but so can a few places in TextureGroup, so better to do all at once. The full generation of overlaps could probably be improved in a similar way.
I recommend testing a few games to make sure nothing breaks.
* Address feedback
2023-03-14 16:33:44 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a view from the group, removing it from all overlap lists.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="view">View to remove from the group</param>
|
|
|
|
|
public void RemoveView(Texture view)
|
|
|
|
|
{
|
|
|
|
|
int offset = FindOffset(view);
|
|
|
|
|
|
|
|
|
|
foreach (TextureGroupHandle handle in _handles)
|
|
|
|
|
{
|
|
|
|
|
handle.RemoveOverlap(offset, view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Inherit handle state from an old set of handles, such as modified and dirty flags.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="oldHandles">The set of handles to inherit state from</param>
|
|
|
|
|
/// <param name="handles">The set of handles inheriting the state</param>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// <param name="relativeOffset">The offset of the old handles in relation to the new ones</param>
|
|
|
|
|
private void InheritHandles(TextureGroupHandle[] oldHandles, TextureGroupHandle[] handles, int relativeOffset)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
foreach (var group in handles)
|
|
|
|
|
{
|
|
|
|
|
foreach (var handle in group.Handles)
|
|
|
|
|
{
|
|
|
|
|
bool dirty = false;
|
|
|
|
|
|
|
|
|
|
foreach (var oldGroup in oldHandles)
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
if (group.OverlapsWith(oldGroup.Offset + relativeOffset, oldGroup.Size))
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
foreach (var oldHandle in oldGroup.Handles)
|
|
|
|
|
{
|
|
|
|
|
if (handle.OverlapsWith(oldHandle.Address, oldHandle.Size))
|
|
|
|
|
{
|
|
|
|
|
dirty |= oldHandle.Dirty;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
|
|
|
|
group.Inherit(oldGroup, group.Offset == oldGroup.Offset + relativeOffset);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dirty && !handle.Dirty)
|
2022-01-09 11:28:48 -05:00
|
|
|
|
{
|
2021-03-02 17:30:54 -05:00
|
|
|
|
handle.Reprotect(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (group.Modified)
|
|
|
|
|
{
|
|
|
|
|
handle.RegisterAction((address, size) => FlushAction(group, address, size));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
|
|
|
|
foreach (var oldGroup in oldHandles)
|
|
|
|
|
{
|
|
|
|
|
oldGroup.Modified = false;
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Inherit state from another texture group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="other">The texture group to inherit from</param>
|
|
|
|
|
public void Inherit(TextureGroup other)
|
|
|
|
|
{
|
|
|
|
|
bool layerViews = _hasLayerViews || other._hasLayerViews;
|
|
|
|
|
bool mipViews = _hasMipViews || other._hasMipViews;
|
|
|
|
|
|
|
|
|
|
if (layerViews != _hasLayerViews || mipViews != _hasMipViews)
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = layerViews;
|
|
|
|
|
_hasMipViews = mipViews;
|
|
|
|
|
|
|
|
|
|
RecalculateHandleRegions();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
foreach (TextureIncompatibleOverlap incompatible in other._incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
RegisterIncompatibleOverlap(incompatible, false);
|
|
|
|
|
|
|
|
|
|
incompatible.Group._incompatibleOverlaps.RemoveAll(overlap => overlap.Group == other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int relativeOffset = Storage.Range.FindOffset(other.Storage.Range);
|
|
|
|
|
|
|
|
|
|
InheritHandles(other._handles, _handles, relativeOffset);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Replace the current handles with the new handles. It is assumed that the new handles start dirty.
|
|
|
|
|
/// The dirty flags from the previous handles will be kept.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="handles">The handles to replace the current handles with</param>
|
2023-03-14 16:08:44 -04:00
|
|
|
|
/// <param name="rangeChanged">True if the storage memory range changed since the last region handle generation</param>
|
|
|
|
|
private void ReplaceHandles(TextureGroupHandle[] handles, bool rangeChanged)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
if (_handles != null)
|
|
|
|
|
{
|
|
|
|
|
// When replacing handles, they should start as non-dirty.
|
|
|
|
|
|
|
|
|
|
foreach (TextureGroupHandle groupHandle in handles)
|
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
if (rangeChanged)
|
|
|
|
|
{
|
|
|
|
|
// When the storage range changes, this becomes a little different.
|
|
|
|
|
// If a range does not match one in the original, treat it as modified.
|
|
|
|
|
// It has been newly mapped and its data must be synchronized.
|
|
|
|
|
|
|
|
|
|
if (groupHandle.Handles.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var oldGroup in _handles)
|
|
|
|
|
{
|
|
|
|
|
if (!groupHandle.OverlapsWith(oldGroup.Offset, oldGroup.Size))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (CpuRegionHandle handle in groupHandle.Handles)
|
|
|
|
|
{
|
|
|
|
|
bool hasMatch = false;
|
|
|
|
|
|
|
|
|
|
foreach (var oldHandle in oldGroup.Handles)
|
|
|
|
|
{
|
|
|
|
|
if (oldHandle.RangeEquals(handle))
|
|
|
|
|
{
|
|
|
|
|
hasMatch = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasMatch)
|
|
|
|
|
{
|
|
|
|
|
handle.Reprotect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2023-03-14 16:08:44 -04:00
|
|
|
|
foreach (CpuRegionHandle handle in groupHandle.Handles)
|
|
|
|
|
{
|
|
|
|
|
handle.Reprotect();
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
InheritHandles(_handles, handles, 0);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
foreach (var oldGroup in _handles)
|
|
|
|
|
{
|
|
|
|
|
foreach (var oldHandle in oldGroup.Handles)
|
|
|
|
|
{
|
|
|
|
|
oldHandle.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_handles = handles;
|
|
|
|
|
_loadNeeded = new bool[_handles.Length];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Recalculate handle regions for this texture group, and inherit existing state into the new handles.
|
|
|
|
|
/// </summary>
|
2023-03-14 16:08:44 -04:00
|
|
|
|
/// <param name="rangeChanged">True if the storage memory range changed since the last region handle generation</param>
|
|
|
|
|
private void RecalculateHandleRegions(bool rangeChanged = false)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle[] handles;
|
|
|
|
|
|
|
|
|
|
if (!(_hasMipViews || _hasLayerViews))
|
|
|
|
|
{
|
|
|
|
|
// Single dirty region.
|
|
|
|
|
var cpuRegionHandles = new CpuRegionHandle[TextureRange.Count];
|
2022-02-22 11:34:16 -05:00
|
|
|
|
int count = 0;
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < TextureRange.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var currentRange = TextureRange.GetSubRange(i);
|
2022-02-22 11:34:16 -05:00
|
|
|
|
if (currentRange.Address != MemoryManager.PteUnmapped)
|
|
|
|
|
{
|
|
|
|
|
cpuRegionHandles[count++] = GenerateHandle(currentRange.Address, currentRange.Size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count != TextureRange.Count)
|
|
|
|
|
{
|
|
|
|
|
Array.Resize(ref cpuRegionHandles, count);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
var groupHandle = new TextureGroupHandle(this, 0, Storage.Size, _views, 0, 0, 0, _allOffsets.Length, cpuRegionHandles);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
foreach (CpuRegionHandle handle in cpuRegionHandles)
|
|
|
|
|
{
|
|
|
|
|
handle.RegisterDirtyEvent(() => DirtyAction(groupHandle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handles = new TextureGroupHandle[] { groupHandle };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Get views for the host texture.
|
|
|
|
|
// It's worth noting that either the texture has layer views or mip views when getting to this point, which simplifies the logic a little.
|
|
|
|
|
// Depending on if the texture is 3d, either the mip views imply that layer views are present (2d) or the other way around (3d).
|
|
|
|
|
// This is enforced by the way the texture matched as a view, so we don't need to check.
|
|
|
|
|
|
|
|
|
|
int layerHandles = _hasLayerViews ? _layers : 1;
|
|
|
|
|
int levelHandles = _hasMipViews ? _levels : 1;
|
|
|
|
|
|
|
|
|
|
int handleIndex = 0;
|
|
|
|
|
|
|
|
|
|
if (_is3D)
|
|
|
|
|
{
|
|
|
|
|
var handlesList = new List<TextureGroupHandle>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < levelHandles; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < layerHandles; j++)
|
|
|
|
|
{
|
|
|
|
|
(int viewStart, int views) = Get3DLevelRange(i);
|
|
|
|
|
viewStart += j;
|
|
|
|
|
views = _hasLayerViews ? 1 : views; // A layer view is also a mip view.
|
|
|
|
|
|
|
|
|
|
handlesList.Add(GenerateHandles(viewStart, views));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layerHandles = Math.Max(1, layerHandles >> 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handles = handlesList.ToArray();
|
2022-01-09 11:28:48 -05:00
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
handles = new TextureGroupHandle[layerHandles * levelHandles];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < layerHandles; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < levelHandles; j++)
|
|
|
|
|
{
|
|
|
|
|
int viewStart = j + i * _levels;
|
|
|
|
|
int views = _hasMipViews ? 1 : _levels; // A mip view is also a layer view.
|
|
|
|
|
|
|
|
|
|
handles[handleIndex++] = GenerateHandles(viewStart, views);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:08:44 -04:00
|
|
|
|
ReplaceHandles(handles, rangeChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Regenerates handles when the storage range has been remapped.
|
|
|
|
|
/// This forces the regions to be fully subdivided.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RangeChanged()
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = true;
|
|
|
|
|
_hasMipViews = true;
|
|
|
|
|
|
|
|
|
|
RecalculateHandleRegions(true);
|
|
|
|
|
|
|
|
|
|
SignalAllDirty();
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensure that there is a handle for each potential texture view. Required for copy dependencies to work.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void EnsureFullSubdivision()
|
|
|
|
|
{
|
|
|
|
|
if (!(_hasLayerViews && _hasMipViews))
|
|
|
|
|
{
|
|
|
|
|
_hasLayerViews = true;
|
|
|
|
|
_hasMipViews = true;
|
|
|
|
|
|
|
|
|
|
RecalculateHandleRegions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a copy dependency between this texture group, and a texture at a given layer/level offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="other">The view compatible texture to create a dependency to</param>
|
|
|
|
|
/// <param name="firstLayer">The base layer of the given texture relative to the storage</param>
|
|
|
|
|
/// <param name="firstLevel">The base level of the given texture relative to the storage</param>
|
|
|
|
|
/// <param name="copyTo">True if this texture is first copied to the given one, false for the opposite direction</param>
|
|
|
|
|
public void CreateCopyDependency(Texture other, int firstLayer, int firstLevel, bool copyTo)
|
|
|
|
|
{
|
|
|
|
|
TextureGroup otherGroup = other.Group;
|
|
|
|
|
|
|
|
|
|
EnsureFullSubdivision();
|
|
|
|
|
otherGroup.EnsureFullSubdivision();
|
|
|
|
|
|
|
|
|
|
// Get the location of each texture within its storage, so we can find the handles to apply the dependency to.
|
|
|
|
|
// This can consist of multiple disjoint regions, for example if this is a mip slice of an array texture.
|
|
|
|
|
|
|
|
|
|
var targetRange = new List<(int BaseHandle, int RegionCount)>();
|
|
|
|
|
var otherRange = new List<(int BaseHandle, int RegionCount)>();
|
|
|
|
|
|
|
|
|
|
EvaluateRelevantHandles(firstLayer, firstLevel, other.Info.GetSlices(), other.Info.Levels, (baseHandle, regionCount, split) => targetRange.Add((baseHandle, regionCount)));
|
|
|
|
|
otherGroup.EvaluateRelevantHandles(other, (baseHandle, regionCount, split) => otherRange.Add((baseHandle, regionCount)));
|
|
|
|
|
|
|
|
|
|
int targetIndex = 0;
|
|
|
|
|
int otherIndex = 0;
|
|
|
|
|
(int Handle, int RegionCount) targetRegion = (0, 0);
|
|
|
|
|
(int Handle, int RegionCount) otherRegion = (0, 0);
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (targetRegion.RegionCount == 0)
|
|
|
|
|
{
|
|
|
|
|
if (targetIndex >= targetRange.Count)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
targetRegion = targetRange[targetIndex++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (otherRegion.RegionCount == 0)
|
|
|
|
|
{
|
|
|
|
|
if (otherIndex >= otherRange.Count)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
otherRegion = otherRange[otherIndex++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextureGroupHandle handle = _handles[targetRegion.Handle++];
|
|
|
|
|
TextureGroupHandle otherHandle = other.Group._handles[otherRegion.Handle++];
|
|
|
|
|
|
|
|
|
|
targetRegion.RegionCount--;
|
|
|
|
|
otherRegion.RegionCount--;
|
|
|
|
|
|
|
|
|
|
handle.CreateCopyDependency(otherHandle, copyTo);
|
|
|
|
|
|
|
|
|
|
// If "copyTo" is true, this texture must copy to the other.
|
|
|
|
|
// Otherwise, it must copy to this texture.
|
|
|
|
|
|
|
|
|
|
if (copyTo)
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
otherHandle.Copy(_context, handle);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
handle.Copy(_context, otherHandle);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-09 11:28:48 -05:00
|
|
|
|
/// Creates a copy dependency to another texture group, where handles overlap.
|
|
|
|
|
/// Scans through all handles to find compatible patches in the other group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="other">The texture group that overlaps this one</param>
|
|
|
|
|
/// <param name="copyTo">True if this texture is first copied to the given one, false for the opposite direction</param>
|
|
|
|
|
public void CreateCopyDependency(TextureGroup other, bool copyTo)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _allOffsets.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
(int layer, int level) = GetLayerLevelForView(i);
|
|
|
|
|
MultiRange handleRange = Storage.Range.GetSlice((ulong)_allOffsets[i], 1);
|
|
|
|
|
ulong handleBase = handleRange.GetSubRange(0).Address;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < other._handles.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
(int otherLayer, int otherLevel) = other.GetLayerLevelForView(j);
|
|
|
|
|
MultiRange otherHandleRange = other.Storage.Range.GetSlice((ulong)other._allOffsets[j], 1);
|
|
|
|
|
ulong otherHandleBase = otherHandleRange.GetSubRange(0).Address;
|
|
|
|
|
|
|
|
|
|
if (handleBase == otherHandleBase)
|
|
|
|
|
{
|
|
|
|
|
// Check if the two sizes are compatible.
|
|
|
|
|
TextureInfo info = Storage.Info;
|
|
|
|
|
TextureInfo otherInfo = other.Storage.Info;
|
|
|
|
|
|
2022-02-22 11:34:16 -05:00
|
|
|
|
if (TextureCompatibility.ViewLayoutCompatible(info, otherInfo, level, otherLevel) &&
|
2022-01-09 11:28:48 -05:00
|
|
|
|
TextureCompatibility.CopySizeMatches(info, otherInfo, level, otherLevel))
|
|
|
|
|
{
|
|
|
|
|
// These textures are copy compatible. Create the dependency.
|
|
|
|
|
|
|
|
|
|
EnsureFullSubdivision();
|
|
|
|
|
other.EnsureFullSubdivision();
|
|
|
|
|
|
|
|
|
|
TextureGroupHandle handle = _handles[i];
|
|
|
|
|
TextureGroupHandle otherHandle = other._handles[j];
|
|
|
|
|
|
|
|
|
|
handle.CreateCopyDependency(otherHandle, copyTo);
|
|
|
|
|
|
|
|
|
|
// If "copyTo" is true, this texture must copy to the other.
|
|
|
|
|
// Otherwise, it must copy to this texture.
|
|
|
|
|
|
|
|
|
|
if (copyTo)
|
|
|
|
|
{
|
|
|
|
|
otherHandle.Copy(_context, handle);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
handle.Copy(_context, otherHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers another texture group as an incompatible overlap, if not already registered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="other">The texture group to add to the incompatible overlaps list</param>
|
|
|
|
|
/// <param name="copy">True if the overlap should register copy dependencies</param>
|
|
|
|
|
public void RegisterIncompatibleOverlap(TextureIncompatibleOverlap other, bool copy)
|
|
|
|
|
{
|
|
|
|
|
if (!_incompatibleOverlaps.Exists(overlap => overlap.Group == other.Group))
|
|
|
|
|
{
|
|
|
|
|
if (copy && other.Compatibility == TextureViewCompatibility.LayoutIncompatible)
|
|
|
|
|
{
|
|
|
|
|
// Any of the group's views may share compatibility, even if the parents do not fully.
|
|
|
|
|
CreateCopyDependency(other.Group, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_incompatibleOverlaps.Add(other);
|
|
|
|
|
other.Group._incompatibleOverlaps.Add(new TextureIncompatibleOverlap(this, other.Compatibility));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
other.Group.SignalIncompatibleOverlapModified();
|
|
|
|
|
SignalIncompatibleOverlapModified();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear modified flags in the given range.
|
|
|
|
|
/// This will stop any GPU written data from flushing or copying to dependent textures.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="range">The range to clear modified flags in</param>
|
|
|
|
|
/// <param name="ignore">Ignore handles that have a copy dependency to the specified group</param>
|
|
|
|
|
public void ClearModified(MultiRange range, TextureGroup ignore = null)
|
|
|
|
|
{
|
|
|
|
|
TextureGroupHandle[] handles = _handles;
|
|
|
|
|
|
|
|
|
|
foreach (TextureGroupHandle handle in handles)
|
|
|
|
|
{
|
|
|
|
|
// Handles list is not modified by another thread, only replaced, so this is thread safe.
|
|
|
|
|
// Remove modified flags from all overlapping handles, so that the textures don't flush to unmapped/remapped GPU memory.
|
|
|
|
|
|
|
|
|
|
MultiRange subRange = Storage.Range.GetSlice((ulong)handle.Offset, (ulong)handle.Size);
|
|
|
|
|
|
|
|
|
|
if (range.OverlapsWith(subRange))
|
|
|
|
|
{
|
|
|
|
|
if ((ignore == null || !handle.HasDependencyTo(ignore)) && handle.Modified)
|
|
|
|
|
{
|
|
|
|
|
handle.Modified = false;
|
|
|
|
|
Storage.SignalModifiedDirty();
|
|
|
|
|
|
|
|
|
|
lock (handle.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture texture in handle.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
texture.SignalModifiedDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Storage.SignalModifiedDirty();
|
|
|
|
|
|
|
|
|
|
if (_views != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture texture in _views)
|
|
|
|
|
{
|
|
|
|
|
texture.SignalModifiedDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A flush has been requested on a tracked region. Flush texture data for the given handle.
|
2021-03-02 17:30:54 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="handle">The handle this flush action is for</param>
|
|
|
|
|
/// <param name="address">The address of the flushing memory access</param>
|
|
|
|
|
/// <param name="size">The size of the flushing memory access</param>
|
|
|
|
|
public void FlushAction(TextureGroupHandle handle, ulong address, ulong size)
|
|
|
|
|
{
|
2023-01-16 23:13:24 -05:00
|
|
|
|
// If the page size is larger than 4KB, we will have a lot of false positives for flushing.
|
|
|
|
|
// Let's avoid flushing textures that are unlikely to be read from CPU to improve performance
|
|
|
|
|
// on those platforms.
|
|
|
|
|
if (!_physicalMemory.Supports4KBPages && !Storage.Info.IsLinear && !_context.IsGpuThread())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Fix various issues with texture sync (#3302)
* Fix various issues with texture sync
A variable called _actionRegistered is used to keep track of whether a tracking action has been registered for a given texture group handle. This variable is set when the action is registered, and should be unset when it is consumed. This is used to skip registering the tracking action if it's already registered, saving some time for render targets that are modified very often.
There were two issues with this. The worst issue was that the tracking action handler exits early if the handle's modified flag is false... which means that it never reset _actionRegistered, as that was done within the Sync() method called later. The second issue was that this variable was set true after the sync action was registered, so it was technically possible for the action to run immediately, set the flag to false, then set it to true.
Both situations would lead to the action never being registered again, as the texture group handle would be sure the action is already registered. This breaks the texture for the remaining runtime, or until it is disposed.
It was also possible for a texture to register sync once, then on future frames the last modified sync number did not update. This may have caused some more minor issues.
Seems to fix the Xenoblade flashing bug. Obviously this needs a lot of testing, since it was random chance. I typically had the most luck getting it to happen by switching time of day on the event theatre screen for a while, then entering the equipment screen by pressing X on an event.
May also fix weird things like random chance air swimming in BOTW, maybe a few texture streaming bugs.
* Exchange rather than CompareExchange
2022-04-29 17:34:11 -04:00
|
|
|
|
// There is a small gap here where the action is removed but _actionRegistered is still 1.
|
|
|
|
|
// In this case it will skip registering the action, but here we are already handling it,
|
|
|
|
|
// so there shouldn't be any issue as it's the same handler for all actions.
|
|
|
|
|
|
|
|
|
|
handle.ClearActionRegistered();
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
if (!handle.Modified)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
2023-01-14 09:23:57 -05:00
|
|
|
|
bool isGpuThread = _context.IsGpuThread();
|
|
|
|
|
|
|
|
|
|
if (isGpuThread)
|
|
|
|
|
{
|
|
|
|
|
// No need to wait if we're on the GPU thread, we can just clear the modified flag immediately.
|
|
|
|
|
handle.Modified = false;
|
|
|
|
|
}
|
2023-01-13 21:46:45 -05:00
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
_context.Renderer.BackgroundContextAction(() =>
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2023-01-14 09:23:57 -05:00
|
|
|
|
if (!isGpuThread)
|
|
|
|
|
{
|
|
|
|
|
handle.Sync(_context);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
Storage.SignalModifiedDirty();
|
|
|
|
|
|
|
|
|
|
lock (handle.Overlaps)
|
2021-03-02 17:30:54 -05:00
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
foreach (Texture texture in handle.Overlaps)
|
|
|
|
|
{
|
|
|
|
|
texture.SignalModifiedDirty();
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:28:48 -05:00
|
|
|
|
if (TextureCompatibility.CanTextureFlush(Storage.Info, _context.Capabilities))
|
|
|
|
|
{
|
|
|
|
|
FlushSliceRange(false, handle.BaseSlice, handle.BaseSlice + handle.SliceCount, Storage.GetFlushTexture());
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dispose this texture group, disposing all related memory tracking handles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
foreach (TextureGroupHandle group in _handles)
|
|
|
|
|
{
|
|
|
|
|
group.Dispose();
|
|
|
|
|
}
|
2022-01-09 11:28:48 -05:00
|
|
|
|
|
|
|
|
|
foreach (TextureIncompatibleOverlap incompatible in _incompatibleOverlaps)
|
|
|
|
|
{
|
|
|
|
|
incompatible.Group._incompatibleOverlaps.RemoveAll(overlap => overlap.Group == this);
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|