Change image format view handling to allow view incompatible formats (#7311)
* Allow creating texture aliases on texture pool * Delete old image format override code * New format incompatible alias * Missing bounds check * GetForBinding now takes FormatInfo * Make FormatInfo struct more compact
This commit is contained in:
parent
ccf96bf5e6
commit
eb8132b627
31 changed files with 294 additions and 279 deletions
|
@ -82,7 +82,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
private readonly ImageRef[] _imageRefs;
|
||||
private readonly TextureBuffer[] _bufferTextureRefs;
|
||||
private readonly TextureBuffer[] _bufferImageRefs;
|
||||
private readonly Format[] _bufferImageFormats;
|
||||
|
||||
private ArrayRef<TextureArray>[] _textureArrayRefs;
|
||||
private ArrayRef<ImageArray>[] _imageArrayRefs;
|
||||
|
@ -141,7 +140,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_imageRefs = new ImageRef[Constants.MaxImageBindings * 2];
|
||||
_bufferTextureRefs = new TextureBuffer[Constants.MaxTextureBindings * 2];
|
||||
_bufferImageRefs = new TextureBuffer[Constants.MaxImageBindings * 2];
|
||||
_bufferImageFormats = new Format[Constants.MaxImageBindings * 2];
|
||||
|
||||
_textureArrayRefs = Array.Empty<ArrayRef<TextureArray>>();
|
||||
_imageArrayRefs = Array.Empty<ArrayRef<ImageArray>>();
|
||||
|
@ -391,17 +389,11 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_dirty = DirtyFlags.All;
|
||||
}
|
||||
|
||||
public void SetImage(
|
||||
CommandBufferScoped cbs,
|
||||
ShaderStage stage,
|
||||
int binding,
|
||||
ITexture image,
|
||||
Format imageFormat)
|
||||
public void SetImage(CommandBufferScoped cbs, ShaderStage stage, int binding, ITexture image)
|
||||
{
|
||||
if (image is TextureBuffer imageBuffer)
|
||||
{
|
||||
_bufferImageRefs[binding] = imageBuffer;
|
||||
_bufferImageFormats[binding] = imageFormat;
|
||||
}
|
||||
else if (image is TextureView view)
|
||||
{
|
||||
|
@ -410,13 +402,12 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
iRef.View?.ClearUsage(FeedbackLoopHazards);
|
||||
view?.PrepareForUsage(cbs, stage.ConvertToPipelineStageFlags(), FeedbackLoopHazards);
|
||||
|
||||
iRef = new(stage, view, view.GetView(imageFormat).GetIdentityImageView());
|
||||
iRef = new(stage, view, view.GetIdentityImageView());
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageRefs[binding] = default;
|
||||
_bufferImageRefs[binding] = null;
|
||||
_bufferImageFormats[binding] = default;
|
||||
}
|
||||
|
||||
SignalDirty(DirtyFlags.Image);
|
||||
|
@ -923,7 +914,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
bufferImages[i] = _bufferImageRefs[binding + i]?.GetBufferView(cbs, _bufferImageFormats[binding + i], true) ?? default;
|
||||
bufferImages[i] = _bufferImageRefs[binding + i]?.GetBufferView(cbs, true) ?? default;
|
||||
}
|
||||
|
||||
tu.Push<BufferView>(bufferImages[..count]);
|
||||
|
|
|
@ -154,7 +154,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
int dispatchY = (height + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
|
||||
|
||||
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, buffer.Range) });
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _intermediaryTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _intermediaryTexture.GetView(FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format)));
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
_pipeline.ComputeBarrier();
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
|
||||
var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
|
||||
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _texture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _texture.GetView(FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format)));
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
|
||||
_pipeline.ComputeBarrier();
|
||||
|
|
|
@ -219,7 +219,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
|
||||
buffer.Holder.SetDataUnchecked(buffer.Offset, resolutionBuffer);
|
||||
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, buffer.Range) });
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _edgeOutputTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _edgeOutputTexture.GetView(FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format)));
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
_pipeline.ComputeBarrier();
|
||||
|
||||
|
@ -229,7 +229,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, _edgeOutputTexture, _samplerLinear);
|
||||
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 3, _areaTexture, _samplerLinear);
|
||||
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 4, _searchTexture, _samplerLinear);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _blendOutputTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _blendOutputTexture.GetView(FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format)));
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
_pipeline.ComputeBarrier();
|
||||
|
||||
|
@ -238,7 +238,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
_pipeline.Specialize(_specConstants);
|
||||
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 3, _blendOutputTexture, _samplerLinear);
|
||||
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, view, _samplerLinear);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _outputTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, _outputTexture.GetView(FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format)));
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
_pipeline.ComputeBarrier();
|
||||
|
||||
|
|
|
@ -1039,7 +1039,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
var dstView = Create2DLayerView(dst, dstLayer + z, dstLevel + l);
|
||||
|
||||
_pipeline.SetTextureAndSamplerIdentitySwizzle(ShaderStage.Compute, 0, srcView, null);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, dstView, dstFormat);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, dstView.GetView(dstFormat));
|
||||
|
||||
int dispatchX = (Math.Min(srcView.Info.Width, dstView.Info.Width) + 31) / 32;
|
||||
int dispatchY = (Math.Min(srcView.Info.Height, dstView.Info.Height) + 31) / 32;
|
||||
|
@ -1168,7 +1168,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
var dstView = Create2DLayerView(dst, dstLayer + z, 0);
|
||||
|
||||
_pipeline.SetTextureAndSamplerIdentitySwizzle(ShaderStage.Compute, 0, srcView, null);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, dstView, format);
|
||||
_pipeline.SetImage(ShaderStage.Compute, 0, dstView.GetView(format));
|
||||
|
||||
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
public TextureStorage Storage;
|
||||
public TextureView View;
|
||||
public GAL.Format ImageFormat;
|
||||
}
|
||||
|
||||
private readonly TextureRef[] _textureRefs;
|
||||
|
@ -52,16 +51,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_isBuffer = isBuffer;
|
||||
}
|
||||
|
||||
public void SetFormats(int index, GAL.Format[] imageFormats)
|
||||
{
|
||||
for (int i = 0; i < imageFormats.Length; i++)
|
||||
{
|
||||
_textureRefs[index + i].ImageFormat = imageFormats[i];
|
||||
}
|
||||
|
||||
SetDirty();
|
||||
}
|
||||
|
||||
public void SetImages(int index, ITexture[] images)
|
||||
{
|
||||
for (int i = 0; i < images.Length; i++)
|
||||
|
@ -142,7 +131,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
ref var texture = ref textures[i];
|
||||
ref var refs = ref _textureRefs[i];
|
||||
|
||||
if (i > 0 && _textureRefs[i - 1].View == refs.View && _textureRefs[i - 1].ImageFormat == refs.ImageFormat)
|
||||
if (i > 0 && _textureRefs[i - 1].View == refs.View)
|
||||
{
|
||||
texture = textures[i - 1];
|
||||
|
||||
|
@ -150,7 +139,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
}
|
||||
|
||||
texture.ImageLayout = ImageLayout.General;
|
||||
texture.ImageView = refs.View?.GetView(refs.ImageFormat).GetIdentityImageView().Get(cbs).Value ?? default;
|
||||
texture.ImageView = refs.View?.GetIdentityImageView().Get(cbs).Value ?? default;
|
||||
|
||||
if (texture.ImageView.Handle == 0)
|
||||
{
|
||||
|
@ -167,7 +156,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
for (int i = 0; i < bufferTextures.Length; i++)
|
||||
{
|
||||
bufferTextures[i] = _bufferTextureRefs[i]?.GetBufferView(cbs, _textureRefs[i].ImageFormat, true) ?? default;
|
||||
bufferTextures[i] = _bufferTextureRefs[i]?.GetBufferView(cbs, true) ?? default;
|
||||
}
|
||||
|
||||
return bufferTextures;
|
||||
|
|
|
@ -836,9 +836,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
SignalStateChange();
|
||||
}
|
||||
|
||||
public void SetImage(ShaderStage stage, int binding, ITexture image, Format imageFormat)
|
||||
public void SetImage(ShaderStage stage, int binding, ITexture image)
|
||||
{
|
||||
_descriptorSetUpdater.SetImage(Cbs, stage, binding, image, imageFormat);
|
||||
_descriptorSetUpdater.SetImage(Cbs, stage, binding, image);
|
||||
}
|
||||
|
||||
public void SetImage(int binding, Auto<DisposableImageView> image)
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
private int _offset;
|
||||
private int _size;
|
||||
private Auto<DisposableBufferView> _bufferView;
|
||||
private Dictionary<Format, Auto<DisposableBufferView>> _selfManagedViews;
|
||||
|
||||
private int _bufferCount;
|
||||
|
||||
|
@ -80,16 +79,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
private void ReleaseImpl()
|
||||
{
|
||||
if (_selfManagedViews != null)
|
||||
{
|
||||
foreach (var bufferView in _selfManagedViews.Values)
|
||||
{
|
||||
bufferView.Dispose();
|
||||
}
|
||||
|
||||
_selfManagedViews = null;
|
||||
}
|
||||
|
||||
_bufferView?.Dispose();
|
||||
_bufferView = null;
|
||||
}
|
||||
|
@ -137,28 +126,5 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
return _bufferView?.Get(cbs, _offset, _size, write).Value ?? default;
|
||||
}
|
||||
|
||||
public BufferView GetBufferView(CommandBufferScoped cbs, Format format, bool write)
|
||||
{
|
||||
var vkFormat = FormatTable.GetFormat(format);
|
||||
if (vkFormat == VkFormat)
|
||||
{
|
||||
return GetBufferView(cbs, write);
|
||||
}
|
||||
|
||||
if (_selfManagedViews != null && _selfManagedViews.TryGetValue(format, out var bufferView))
|
||||
{
|
||||
return bufferView.Get(cbs, _offset, _size, write).Value;
|
||||
}
|
||||
|
||||
bufferView = _gd.BufferManager.CreateView(_bufferHandle, vkFormat, _offset, _size, ReleaseImpl);
|
||||
|
||||
if (bufferView != null)
|
||||
{
|
||||
(_selfManagedViews ??= new Dictionary<Format, Auto<DisposableBufferView>>()).Add(format, bufferView);
|
||||
}
|
||||
|
||||
return bufferView?.Get(cbs, _offset, _size, write).Value ?? default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue