2021-06-23 19:51:41 -04:00
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2021-07-11 16:20:40 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Engine.Types;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
|
|
|
{
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Texture manager.
|
|
|
|
|
/// </summary>
|
2019-12-31 17:09:49 -05:00
|
|
|
|
class TextureManager : IDisposable
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-12-29 18:26:37 -05:00
|
|
|
|
private readonly GpuContext _context;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
private readonly TextureBindingsManager _cpBindingsManager;
|
|
|
|
|
private readonly TextureBindingsManager _gpBindingsManager;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
private readonly Texture[] _rtColors;
|
|
|
|
|
private readonly ITexture[] _rtHostColors;
|
2021-01-17 13:44:34 -05:00
|
|
|
|
private Texture _rtDepthStencil;
|
2019-12-29 18:26:37 -05:00
|
|
|
|
private ITexture _rtHostDs;
|
|
|
|
|
|
2020-07-06 22:41:07 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The scaling factor applied to all currently bound render targets.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float RenderTargetScale { get; private set; } = 1f;
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// Creates a new instance of the texture manager.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// <param name="context">GPU context that the texture manager belongs to</param>
|
|
|
|
|
/// <param name="channel">GPU channel that the texture manager belongs to</param>
|
|
|
|
|
public TextureManager(GpuContext context, GpuChannel channel)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-17 22:41:18 -04:00
|
|
|
|
_context = context;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-11-22 12:17:06 -05:00
|
|
|
|
TexturePoolCache texturePoolCache = new TexturePoolCache(context);
|
|
|
|
|
|
2021-09-28 17:52:27 -04:00
|
|
|
|
float[] scales = new float[64];
|
|
|
|
|
new Span<float>(scales).Fill(1f);
|
|
|
|
|
|
|
|
|
|
_cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, scales, isCompute: true);
|
|
|
|
|
_gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, scales, isCompute: false);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_rtColors = new Texture[Constants.TotalRenderTargets];
|
|
|
|
|
_rtHostColors = new ITexture[Constants.TotalRenderTargets];
|
2019-10-17 22:41:18 -04:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// Rents the texture bindings array of the compute pipeline.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// <param name="count">The number of bindings needed</param>
|
|
|
|
|
/// <returns>The texture bindings array</returns>
|
|
|
|
|
public TextureBindingInfo[] RentComputeTextureBindings(int count)
|
2019-10-17 22:41:18 -04:00
|
|
|
|
{
|
2021-09-19 08:03:05 -04:00
|
|
|
|
return _cpBindingsManager.RentTextureBindings(0, count);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// Rents the texture bindings array for a given stage on the graphics pipeline.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">The index of the shader stage to bind the textures</param>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// <param name="count">The number of bindings needed</param>
|
|
|
|
|
/// <returns>The texture bindings array</returns>
|
|
|
|
|
public TextureBindingInfo[] RentGraphicsTextureBindings(int stage, int count)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-09-19 08:03:05 -04:00
|
|
|
|
return _gpBindingsManager.RentTextureBindings(stage, count);
|
2019-10-17 22:41:18 -04:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// Rents the image bindings array of the compute pipeline.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// <param name="count">The number of bindings needed</param>
|
|
|
|
|
/// <returns>The image bindings array</returns>
|
|
|
|
|
public TextureBindingInfo[] RentComputeImageBindings(int count)
|
2019-10-17 22:41:18 -04:00
|
|
|
|
{
|
2021-09-19 08:03:05 -04:00
|
|
|
|
return _cpBindingsManager.RentImageBindings(0, count);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// Rents the image bindings array for a given stage on the graphics pipeline.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">The index of the shader stage to bind the images</param>
|
2021-09-19 08:03:05 -04:00
|
|
|
|
/// <param name="count">The number of bindings needed</param>
|
|
|
|
|
/// <returns>The image bindings array</returns>
|
|
|
|
|
public TextureBindingInfo[] RentGraphicsImageBindings(int stage, int count)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-09-19 08:03:05 -04:00
|
|
|
|
return _gpBindingsManager.RentImageBindings(stage, count);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the texture constant buffer index on the compute pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The texture constant buffer index</param>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void SetComputeTextureBufferIndex(int index)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-17 22:41:18 -04:00
|
|
|
|
_cpBindingsManager.SetTextureBufferIndex(index);
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the texture constant buffer index on the graphics pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The texture constant buffer index</param>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void SetGraphicsTextureBufferIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
_gpBindingsManager.SetTextureBufferIndex(index);
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the current sampler pool on the compute pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gpuVa">The start GPU virtual address of the sampler pool</param>
|
|
|
|
|
/// <param name="maximumId">The maximum ID of the sampler pool</param>
|
2019-12-30 12:44:22 -05:00
|
|
|
|
/// <param name="samplerIndex">The indexing type of the sampler pool</param>
|
2019-12-05 15:34:47 -05:00
|
|
|
|
public void SetComputeSamplerPool(ulong gpuVa, int maximumId, SamplerIndex samplerIndex)
|
2019-10-17 22:41:18 -04:00
|
|
|
|
{
|
2019-12-05 15:34:47 -05:00
|
|
|
|
_cpBindingsManager.SetSamplerPool(gpuVa, maximumId, samplerIndex);
|
2019-10-17 22:41:18 -04:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the current sampler pool on the graphics pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gpuVa">The start GPU virtual address of the sampler pool</param>
|
|
|
|
|
/// <param name="maximumId">The maximum ID of the sampler pool</param>
|
2019-12-30 12:44:22 -05:00
|
|
|
|
/// <param name="samplerIndex">The indexing type of the sampler pool</param>
|
2019-12-05 15:34:47 -05:00
|
|
|
|
public void SetGraphicsSamplerPool(ulong gpuVa, int maximumId, SamplerIndex samplerIndex)
|
2019-10-17 22:41:18 -04:00
|
|
|
|
{
|
2019-12-05 15:34:47 -05:00
|
|
|
|
_gpBindingsManager.SetSamplerPool(gpuVa, maximumId, samplerIndex);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the current texture pool on the compute pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gpuVa">The start GPU virtual address of the texture pool</param>
|
|
|
|
|
/// <param name="maximumId">The maximum ID of the texture pool</param>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void SetComputeTexturePool(ulong gpuVa, int maximumId)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-17 22:41:18 -04:00
|
|
|
|
_cpBindingsManager.SetTexturePool(gpuVa, maximumId);
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the current texture pool on the graphics pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gpuVa">The start GPU virtual address of the texture pool</param>
|
|
|
|
|
/// <param name="maximumId">The maximum ID of the texture pool</param>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void SetGraphicsTexturePool(ulong gpuVa, int maximumId)
|
|
|
|
|
{
|
|
|
|
|
_gpBindingsManager.SetTexturePool(gpuVa, maximumId);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 16:44:51 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check if a texture's scale must be updated to match the configured resolution scale.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">The texture to check</param>
|
|
|
|
|
/// <returns>True if the scale needs updating, false if the scale is up to date</returns>
|
|
|
|
|
private bool ScaleNeedsUpdated(Texture texture)
|
|
|
|
|
{
|
|
|
|
|
return texture != null && !(texture.ScaleMode == TextureScaleMode.Blacklisted || texture.ScaleMode == TextureScaleMode.Undesired) && texture.ScaleFactor != GraphicsConfig.ResScale;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the render target color buffer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The index of the color buffer to set (up to 8)</param>
|
|
|
|
|
/// <param name="color">The color buffer texture</param>
|
2020-07-06 22:41:07 -04:00
|
|
|
|
/// <returns>True if render target scale must be updated.</returns>
|
|
|
|
|
public bool SetRenderTargetColor(int index, Texture color)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2020-07-06 22:41:07 -04:00
|
|
|
|
bool hasValue = color != null;
|
|
|
|
|
bool changesScale = (hasValue != (_rtColors[index] != null)) || (hasValue && RenderTargetScale != color.ScaleFactor);
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
if (_rtColors[index] != color)
|
|
|
|
|
{
|
|
|
|
|
_rtColors[index]?.SignalModifying(false);
|
2021-07-03 00:55:04 -04:00
|
|
|
|
|
|
|
|
|
if (color != null)
|
|
|
|
|
{
|
|
|
|
|
color.SynchronizeMemory();
|
|
|
|
|
color.SignalModifying(true);
|
|
|
|
|
}
|
2021-03-02 17:30:54 -05:00
|
|
|
|
|
|
|
|
|
_rtColors[index] = color;
|
|
|
|
|
}
|
2020-07-06 22:41:07 -04:00
|
|
|
|
|
2021-08-11 16:44:51 -04:00
|
|
|
|
return changesScale || ScaleNeedsUpdated(color);
|
2020-07-06 22:41:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 10:33:39 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the render target depth-stencil buffer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="depthStencil">The depth-stencil buffer texture</param>
|
|
|
|
|
/// <returns>True if render target scale must be updated.</returns>
|
|
|
|
|
public bool SetRenderTargetDepthStencil(Texture depthStencil)
|
|
|
|
|
{
|
|
|
|
|
bool hasValue = depthStencil != null;
|
|
|
|
|
bool changesScale = (hasValue != (_rtDepthStencil != null)) || (hasValue && RenderTargetScale != depthStencil.ScaleFactor);
|
|
|
|
|
|
|
|
|
|
if (_rtDepthStencil != depthStencil)
|
|
|
|
|
{
|
|
|
|
|
_rtDepthStencil?.SignalModifying(false);
|
2021-07-03 00:55:04 -04:00
|
|
|
|
|
|
|
|
|
if (depthStencil != null)
|
|
|
|
|
{
|
|
|
|
|
depthStencil.SynchronizeMemory();
|
|
|
|
|
depthStencil.SignalModifying(true);
|
|
|
|
|
}
|
2021-04-02 10:33:39 -04:00
|
|
|
|
|
|
|
|
|
_rtDepthStencil = depthStencil;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 16:44:51 -04:00
|
|
|
|
return changesScale || ScaleNeedsUpdated(depthStencil);
|
2021-04-02 10:33:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 14:53:23 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the first available bound colour target, or the depth stencil target if not present.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The first bound colour target, otherwise the depth stencil target</returns>
|
|
|
|
|
public Texture GetAnyRenderTarget()
|
|
|
|
|
{
|
|
|
|
|
return _rtColors[0] ?? _rtDepthStencil;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 22:41:07 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the Render Target scale, given the currently bound render targets.
|
|
|
|
|
/// This will update scale to match the configured scale, scale textures that are eligible but not scaled,
|
|
|
|
|
/// and propagate blacklisted status from one texture to the ones bound with it.
|
|
|
|
|
/// </summary>
|
2020-07-13 07:41:30 -04:00
|
|
|
|
/// <param name="singleUse">If this is not -1, it indicates that only the given indexed target will be used.</param>
|
2020-07-06 22:41:07 -04:00
|
|
|
|
public void UpdateRenderTargetScale(int singleUse)
|
|
|
|
|
{
|
|
|
|
|
// Make sure all scales for render targets are at the highest they should be. Blacklisted targets should propagate their scale to the other targets.
|
|
|
|
|
bool mismatch = false;
|
|
|
|
|
bool blacklisted = false;
|
|
|
|
|
bool hasUpscaled = false;
|
2021-08-11 16:44:51 -04:00
|
|
|
|
bool hasUndesired = false;
|
2020-07-06 22:41:07 -04:00
|
|
|
|
float targetScale = GraphicsConfig.ResScale;
|
|
|
|
|
|
|
|
|
|
void ConsiderTarget(Texture target)
|
|
|
|
|
{
|
|
|
|
|
if (target == null) return;
|
|
|
|
|
float scale = target.ScaleFactor;
|
|
|
|
|
|
|
|
|
|
switch (target.ScaleMode)
|
|
|
|
|
{
|
|
|
|
|
case TextureScaleMode.Blacklisted:
|
|
|
|
|
mismatch |= scale != 1f;
|
|
|
|
|
blacklisted = true;
|
|
|
|
|
break;
|
|
|
|
|
case TextureScaleMode.Eligible:
|
|
|
|
|
mismatch = true; // We must make a decision.
|
|
|
|
|
break;
|
2021-08-11 16:44:51 -04:00
|
|
|
|
case TextureScaleMode.Undesired:
|
|
|
|
|
hasUndesired = true;
|
|
|
|
|
mismatch |= scale != 1f || hasUpscaled; // If another target is upscaled, scale this one up too.
|
|
|
|
|
break;
|
2020-07-06 22:41:07 -04:00
|
|
|
|
case TextureScaleMode.Scaled:
|
|
|
|
|
hasUpscaled = true;
|
2021-08-11 16:44:51 -04:00
|
|
|
|
mismatch |= hasUndesired || scale != targetScale; // If the target scale has changed, reset the scale for all targets.
|
2020-07-06 22:41:07 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (singleUse != -1)
|
|
|
|
|
{
|
|
|
|
|
// If only one target is in use (by a clear, for example) the others do not need to be checked for mismatching scale.
|
|
|
|
|
ConsiderTarget(_rtColors[singleUse]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (Texture color in _rtColors)
|
|
|
|
|
{
|
|
|
|
|
ConsiderTarget(color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConsiderTarget(_rtDepthStencil);
|
|
|
|
|
|
|
|
|
|
mismatch |= blacklisted && hasUpscaled;
|
|
|
|
|
|
2021-08-11 16:44:51 -04:00
|
|
|
|
if (blacklisted || (hasUndesired && !hasUpscaled))
|
2020-07-06 22:41:07 -04:00
|
|
|
|
{
|
|
|
|
|
targetScale = 1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mismatch)
|
|
|
|
|
{
|
|
|
|
|
if (blacklisted)
|
|
|
|
|
{
|
|
|
|
|
// Propagate the blacklisted state to the other textures.
|
|
|
|
|
foreach (Texture color in _rtColors)
|
|
|
|
|
{
|
|
|
|
|
color?.BlacklistScale();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rtDepthStencil?.BlacklistScale();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Set the scale of the other textures.
|
|
|
|
|
foreach (Texture color in _rtColors)
|
|
|
|
|
{
|
|
|
|
|
color?.SetScale(targetScale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rtDepthStencil?.SetScale(targetScale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderTargetScale = targetScale;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Commits bindings on the compute pipeline.
|
|
|
|
|
/// </summary>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void CommitComputeBindings()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-26 13:50:52 -04:00
|
|
|
|
// Every time we switch between graphics and compute work,
|
2019-10-17 22:41:18 -04:00
|
|
|
|
// we must rebind everything.
|
|
|
|
|
// Since compute work happens less often, we always do that
|
|
|
|
|
// before and after the compute dispatch.
|
|
|
|
|
_cpBindingsManager.Rebind();
|
|
|
|
|
_cpBindingsManager.CommitBindings();
|
|
|
|
|
_gpBindingsManager.Rebind();
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Commits bindings on the graphics pipeline.
|
|
|
|
|
/// </summary>
|
2019-10-17 22:41:18 -04:00
|
|
|
|
public void CommitGraphicsBindings()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-17 22:41:18 -04:00
|
|
|
|
_gpBindingsManager.CommitBindings();
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-10-17 22:41:18 -04:00
|
|
|
|
UpdateRenderTargets();
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a texture descriptor used on the compute pipeline.
|
|
|
|
|
/// </summary>
|
2021-07-07 19:56:06 -04:00
|
|
|
|
/// <param name="poolGpuVa">GPU virtual address of the texture pool</param>
|
|
|
|
|
/// <param name="bufferIndex">Index of the constant buffer with texture handles</param>
|
|
|
|
|
/// <param name="maximumId">Maximum ID of the texture pool</param>
|
2020-04-21 19:35:28 -04:00
|
|
|
|
/// <param name="handle">Shader "fake" handle of the texture</param>
|
2021-05-19 14:05:43 -04:00
|
|
|
|
/// <param name="cbufSlot">Shader constant buffer slot of the texture</param>
|
2020-04-21 19:35:28 -04:00
|
|
|
|
/// <returns>The texture descriptor</returns>
|
2021-07-07 19:56:06 -04:00
|
|
|
|
public TextureDescriptor GetComputeTextureDescriptor(ulong poolGpuVa, int bufferIndex, int maximumId, int handle, int cbufSlot)
|
2020-04-21 19:35:28 -04:00
|
|
|
|
{
|
2021-07-07 19:56:06 -04:00
|
|
|
|
return _cpBindingsManager.GetTextureDescriptor(poolGpuVa, bufferIndex, maximumId, 0, handle, cbufSlot);
|
2020-04-21 19:35:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a texture descriptor used on the graphics pipeline.
|
|
|
|
|
/// </summary>
|
2021-07-07 19:56:06 -04:00
|
|
|
|
/// <param name="poolGpuVa">GPU virtual address of the texture pool</param>
|
|
|
|
|
/// <param name="bufferIndex">Index of the constant buffer with texture handles</param>
|
|
|
|
|
/// <param name="maximumId">Maximum ID of the texture pool</param>
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <param name="stageIndex">Index of the shader stage where the texture is bound</param>
|
|
|
|
|
/// <param name="handle">Shader "fake" handle of the texture</param>
|
2021-05-19 14:05:43 -04:00
|
|
|
|
/// <param name="cbufSlot">Shader constant buffer slot of the texture</param>
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <returns>The texture descriptor</returns>
|
2021-07-07 19:56:06 -04:00
|
|
|
|
public TextureDescriptor GetGraphicsTextureDescriptor(
|
|
|
|
|
ulong poolGpuVa,
|
|
|
|
|
int bufferIndex,
|
|
|
|
|
int maximumId,
|
|
|
|
|
int stageIndex,
|
|
|
|
|
int handle,
|
|
|
|
|
int cbufSlot)
|
2019-12-15 23:59:46 -05:00
|
|
|
|
{
|
2021-07-07 19:56:06 -04:00
|
|
|
|
return _gpBindingsManager.GetTextureDescriptor(poolGpuVa, bufferIndex, maximumId, stageIndex, handle, cbufSlot);
|
2019-12-15 23:59:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update host framebuffer attachments based on currently bound render target buffers.
|
|
|
|
|
/// </summary>
|
2020-09-23 19:48:34 -04:00
|
|
|
|
public void UpdateRenderTargets()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
|
|
|
|
bool anyChanged = false;
|
|
|
|
|
|
|
|
|
|
if (_rtHostDs != _rtDepthStencil?.HostTexture)
|
|
|
|
|
{
|
|
|
|
|
_rtHostDs = _rtDepthStencil?.HostTexture;
|
|
|
|
|
|
|
|
|
|
anyChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 19:45:01 -04:00
|
|
|
|
for (int index = 0; index < _rtColors.Length; index++)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-30 19:45:01 -04:00
|
|
|
|
ITexture hostTexture = _rtColors[index]?.HostTexture;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-10-30 19:45:01 -04:00
|
|
|
|
if (_rtHostColors[index] != hostTexture)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-10-30 19:45:01 -04:00
|
|
|
|
_rtHostColors[index] = hostTexture;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
anyChanged = true;
|
|
|
|
|
}
|
2019-10-30 19:45:01 -04:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-10-30 19:45:01 -04:00
|
|
|
|
if (anyChanged)
|
|
|
|
|
{
|
|
|
|
|
_context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, _rtHostDs);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 22:41:07 -04:00
|
|
|
|
/// <summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// Forces all textures, samplers, images and render targets to be rebound the next time
|
|
|
|
|
/// CommitGraphicsBindings is called.
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// </summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
public void Rebind()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_gpBindingsManager.Rebind();
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2021-06-23 19:51:41 -04:00
|
|
|
|
for (int index = 0; index < _rtHostColors.Length; index++)
|
2020-10-29 17:57:34 -04:00
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_rtHostColors[index] = null;
|
2020-10-29 17:57:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_rtHostDs = null;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
|
/// <summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// Disposes the texture manager.
|
2019-12-31 17:09:49 -05:00
|
|
|
|
/// It's an error to use the texture manager after disposal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_cpBindingsManager.Dispose();
|
|
|
|
|
_gpBindingsManager.Dispose();
|
2021-06-08 19:00:28 -04:00
|
|
|
|
|
2021-06-23 19:51:41 -04:00
|
|
|
|
for (int i = 0; i < _rtColors.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
_rtColors[i]?.DecrementReferenceCount();
|
|
|
|
|
_rtColors[i] = null;
|
2019-12-31 17:09:49 -05:00
|
|
|
|
}
|
2021-06-23 19:51:41 -04:00
|
|
|
|
|
|
|
|
|
_rtDepthStencil?.DecrementReferenceCount();
|
|
|
|
|
_rtDepthStencil = null;
|
2019-12-31 17:09:49 -05:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
2021-05-19 14:05:43 -04:00
|
|
|
|
}
|