mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-29 17:47:54 +02:00
Compare commits
4
Commits
bed294bb92
...
e80fc00462
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e80fc00462 | ||
|
|
33cbd29c23 | ||
|
|
cfc7c6039f | ||
|
|
ac6db0fe76 |
@@ -381,12 +381,15 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
}
|
||||
|
||||
// Some APIs align the width for copy and render target textures,
|
||||
// so the width may not match in this case for different uses of the same texture.
|
||||
// so the width may not match for different uses of the same texture.
|
||||
// To account for this, we compare the aligned width here.
|
||||
// We expect height to always match exactly, if the texture is the same.
|
||||
// However, matching block footprints are not sufficient for compressed textures;
|
||||
// their logical dimensions must also match.
|
||||
if (alignedWidthMatches && lhsSize.Height == rhsSize.Height)
|
||||
{
|
||||
return (exact && lhsSize.Width != rhsSize.Width) || lhsSize.Width < rhsSize.Width
|
||||
return ((lhs.FormatInfo.IsCompressed || rhs.FormatInfo.IsCompressed) &&
|
||||
(Math.Max(1, lhs.Width >> level) != rhs.Width || Math.Max(1, lhs.Height >> level) != rhs.Height)) ||
|
||||
(exact && lhsSize.Width != rhsSize.Width) || lhsSize.Width < rhsSize.Width
|
||||
? TextureViewCompatibility.CopyOnly
|
||||
: result;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,27 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
private int _colorsCount;
|
||||
private bool _dualSourceBlend;
|
||||
|
||||
public bool HasAttachments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_depthStencil != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int index = 0; index < _colors.Length; index++)
|
||||
{
|
||||
if (_colors[index] != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Framebuffer()
|
||||
{
|
||||
Handle = GL.GenFramebuffer();
|
||||
@@ -34,6 +55,12 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
return Handle;
|
||||
}
|
||||
|
||||
public void SetDefaultSize(int width, int height)
|
||||
{
|
||||
GL.FramebufferParameter(FramebufferTarget.Framebuffer, FramebufferDefaultParameter.FramebufferDefaultWidth, Math.Max(1, width));
|
||||
GL.FramebufferParameter(FramebufferTarget.Framebuffer, FramebufferDefaultParameter.FramebufferDefaultHeight, Math.Max(1, height));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachColor(int index, TextureView color)
|
||||
{
|
||||
@@ -105,13 +132,20 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
_colorsCount = colorsCount;
|
||||
}
|
||||
|
||||
private static void SetDrawBuffersImpl(int colorsCount)
|
||||
private void SetDrawBuffersImpl(int colorsCount)
|
||||
{
|
||||
DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount];
|
||||
|
||||
for (int index = 0; index < colorsCount; index++)
|
||||
{
|
||||
drawBuffers[index] = DrawBuffersEnum.ColorAttachment0 + index;
|
||||
if (_colors[index] != null)
|
||||
{
|
||||
drawBuffers[index] = DrawBuffersEnum.ColorAttachment0 + index;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawBuffers[index] = DrawBuffersEnum.None;
|
||||
}
|
||||
}
|
||||
|
||||
GL.DrawBuffers(colorsCount, drawBuffers);
|
||||
|
||||
@@ -1537,6 +1537,11 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
{
|
||||
DrawCount++;
|
||||
|
||||
if (!_framebuffer.HasAttachments && _viewportArray.Length >= 4)
|
||||
{
|
||||
_framebuffer.SetDefaultSize((int)_viewportArray[2], (int)_viewportArray[3]);
|
||||
}
|
||||
|
||||
_unit0Texture?.Bind(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,19 +70,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
|
||||
Operand bindlessHandle = texOp.GetSource(0);
|
||||
|
||||
if (bindlessHandle.AsgOp is PhiNode phi)
|
||||
{
|
||||
for (int srcIndex = 0; srcIndex < phi.SourcesCount; srcIndex++)
|
||||
{
|
||||
Operand phiSource = phi.GetSource(srcIndex);
|
||||
|
||||
if (phiSource.AsgOp is not PhiNode && !IsBindlessAccessAllowed(phiSource))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!IsBindlessAccessAllowed(bindlessHandle))
|
||||
if (!IsBindlessAccessAllowed(bindlessHandle))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -100,7 +88,10 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
|
||||
texOp.SetSource(0, textureIndex);
|
||||
|
||||
bool hasSampler = !texOp.Inst.IsImage();
|
||||
// Buffer textures use a TIC/BufferView only and never consume a sampler.
|
||||
// Avoiding a sampler descriptor array here is especially important for bindless
|
||||
// texture buffers, where the array can span the entire sampler pool for no benefit.
|
||||
bool hasSampler = !texOp.Inst.IsImage() && texOp.Type != SamplerType.TextureBuffer;
|
||||
|
||||
SetBindingPair textureSetAndBinding = resourceManager.GetTextureOrImageBinding(
|
||||
texOp.Inst,
|
||||
@@ -143,26 +134,112 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
|
||||
private static bool IsBindlessAccessAllowed(Operand bindlessHandle)
|
||||
{
|
||||
if (bindlessHandle.Type == OperandType.ConstantBuffer)
|
||||
{
|
||||
// Bindless access with handles from constant buffer is allowed.
|
||||
// Walk only SSA merges and integer operations that can transparently construct
|
||||
// or select a packed texture/sampler handle. Do not walk arbitrary operations:
|
||||
// finding an unrelated resource load elsewhere in the SSA graph must not enable
|
||||
// descriptor-array access for this handle.
|
||||
const int MaxVisitedOperands = 256;
|
||||
const int MaxDepth = 64;
|
||||
|
||||
return true;
|
||||
Stack<(Operand Operand, int Depth)> work = new();
|
||||
HashSet<Operand> visited = new();
|
||||
|
||||
work.Push((bindlessHandle, 0));
|
||||
|
||||
while (work.Count != 0 && visited.Count < MaxVisitedOperands)
|
||||
{
|
||||
(Operand operand, int depth) = work.Pop();
|
||||
|
||||
if (operand == null || depth > MaxDepth || !visited.Add(operand))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (operand.Type == OperandType.ConstantBuffer)
|
||||
{
|
||||
// Constant buffers are accepted by the existing direct-handle path and
|
||||
// remain accepted when SSA merges or integer handle arithmetic obscure them.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (operand.AsgOp is PhiNode phi)
|
||||
{
|
||||
for (int index = 0; index < phi.SourcesCount; index++)
|
||||
{
|
||||
Operand source = phi.GetSource(index);
|
||||
|
||||
if (source.Type != OperandType.Undefined)
|
||||
{
|
||||
work.Push((source, depth + 1));
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (operand.AsgOp is not Operation operation)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Instruction inst = operation.Inst & Instruction.Mask;
|
||||
|
||||
if (inst == Instruction.Load)
|
||||
{
|
||||
// Preserve the performance restriction. Static CBUF operands are already
|
||||
// accepted above; accept their dynamically indexed Load form as the same
|
||||
// resource class, plus the existing shader-input and storage-buffer sources.
|
||||
// Other loads remain traversal barriers and cannot authorize a pool array.
|
||||
if (operation.StorageKind == StorageKind.ConstantBuffer ||
|
||||
operation.StorageKind == StorageKind.Input ||
|
||||
operation.StorageKind == StorageKind.StorageBuffer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsHandleConstructionOperation(inst))
|
||||
{
|
||||
// Texture/image operations, arbitrary loads, floating-point conversions,
|
||||
// calls and other unrelated calculations are deliberate traversal barriers.
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int index = 0; index < operation.SourcesCount; index++)
|
||||
{
|
||||
work.Push((operation.GetSource(index), depth + 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (bindlessHandle.AsgOp is not Operation handleOp ||
|
||||
handleOp.Inst != Instruction.Load ||
|
||||
(handleOp.StorageKind != StorageKind.Input && handleOp.StorageKind != StorageKind.StorageBuffer))
|
||||
{
|
||||
// Right now, we only allow bindless access when the handle comes from a shader input or storage buffer.
|
||||
// This is an artificial limitation to prevent it from being used in cases where it
|
||||
// would have a large performance impact of loading all textures in the pool.
|
||||
// It might be removed in the future, if we can mitigate the performance impact.
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
private static bool IsHandleConstructionOperation(Instruction inst)
|
||||
{
|
||||
return inst is
|
||||
Instruction.Add or
|
||||
Instruction.Subtract or
|
||||
Instruction.Multiply or
|
||||
Instruction.MultiplyHighS32 or
|
||||
Instruction.MultiplyHighU32 or
|
||||
Instruction.BitwiseAnd or
|
||||
Instruction.BitwiseExclusiveOr or
|
||||
Instruction.BitwiseNot or
|
||||
Instruction.BitwiseOr or
|
||||
Instruction.BitfieldExtractS32 or
|
||||
Instruction.BitfieldExtractU32 or
|
||||
Instruction.BitfieldInsert or
|
||||
Instruction.ShiftLeft or
|
||||
Instruction.ShiftRightS32 or
|
||||
Instruction.ShiftRightU32 or
|
||||
Instruction.MinimumU32 or
|
||||
Instruction.MaximumU32 or
|
||||
Instruction.ClampU32 or
|
||||
Instruction.ConditionalSelect or
|
||||
Instruction.Copy or
|
||||
Instruction.VectorExtract;
|
||||
}
|
||||
|
||||
private static bool TryConvertBindless(BasicBlock block, ResourceManager resourceManager, IGpuAccessor gpuAccessor, TextureOperation texOp)
|
||||
|
||||
@@ -32,6 +32,29 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
public bool HasDepthStencil { get; private set; }
|
||||
public int ColorAttachmentsCount => AttachmentsCount - (HasDepthStencil ? 1 : 0);
|
||||
|
||||
public bool SetVirtualSize(uint width, uint height, uint layers)
|
||||
{
|
||||
if (AttachmentsCount != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
width = Math.Max(1u, width);
|
||||
height = Math.Max(1u, height);
|
||||
layers = Math.Max(1u, layers);
|
||||
|
||||
if (Width == width && Height == height && Layers == layers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Width = width;
|
||||
Height = height;
|
||||
Layers = layers;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public FramebufferParams(Device device, TextureView view, uint width, uint height)
|
||||
{
|
||||
Format format = view.Info.Format;
|
||||
|
||||
@@ -843,6 +843,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
public void SetImage(ShaderStage stage, int binding, ITexture image)
|
||||
{
|
||||
_descriptorSetUpdater.SetImage(Cbs, stage, binding, image);
|
||||
|
||||
if (stage == ShaderStage.Fragment && image is TextureView view)
|
||||
{
|
||||
FramebufferParams?.SetVirtualSize((uint)view.Width, (uint)view.Height, (uint)view.Layers);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetImage(int binding, Auto<DisposableImageView> image)
|
||||
@@ -1607,6 +1612,24 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
|
||||
private bool RecreateGraphicsPipelineIfNeeded()
|
||||
{
|
||||
if (FramebufferParams != null &&
|
||||
FramebufferParams.AttachmentsCount == 0 &&
|
||||
FramebufferParams.Width == 1 &&
|
||||
FramebufferParams.Height == 1 &&
|
||||
DynamicState.ViewportsCount != 0)
|
||||
{
|
||||
// An attachmentless fragment pass can reach its first draw before the storage
|
||||
// image descriptor is rebound. At that point the null framebuffer still has
|
||||
// its constructor fallback of 1x1, even though the guest viewport already
|
||||
// describes the real render area. Seed the virtual framebuffer from that
|
||||
// viewport so the first storage-image draw is not clipped to one pixel.
|
||||
Silk.NET.Vulkan.Viewport viewport = DynamicState.Viewports[0];
|
||||
uint width = (uint)Math.Max(1f, Math.Abs(viewport.Width));
|
||||
uint height = (uint)Math.Max(1f, Math.Abs(viewport.Height));
|
||||
|
||||
FramebufferParams.SetVirtualSize(width, height, 1);
|
||||
}
|
||||
|
||||
if (AutoFlush.ShouldFlushDraw(DrawCount))
|
||||
{
|
||||
Gd.FlushAllCommands();
|
||||
|
||||
+17
-2
@@ -45,6 +45,7 @@ using Ryujinx.UI.Common.Configuration;
|
||||
using Ryujinx.UI.Common.Helper;
|
||||
using Silk.NET.Vulkan;
|
||||
using SkiaSharp;
|
||||
using SPB.Graphics.Exceptions;
|
||||
using SPB.Graphics.Vulkan;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -654,8 +655,22 @@ namespace Ryujinx.Ava
|
||||
|
||||
if (RendererHost.EmbeddedWindow is EmbeddedWindowOpenGL openGlWindow)
|
||||
{
|
||||
// Try to bind the OpenGL context before calling the shutdown event.
|
||||
openGlWindow.MakeCurrent(false, false);
|
||||
try
|
||||
{
|
||||
// Try to bind the OpenGL context before disposing GPU resources.
|
||||
openGlWindow.MakeCurrent();
|
||||
}
|
||||
catch (ContextException e) when (_userChannelPersistence.ShouldRestart)
|
||||
{
|
||||
// ExecuteProgram may detach the old native window before GPU
|
||||
// disposal. Allow the old context to be released with the window
|
||||
// and continue the requested program relaunch.
|
||||
Logger.Warning?.Print(
|
||||
LogClass.UI,
|
||||
$"Failed to bind OpenGL context during program relaunch: {e}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Device.DisposeGpu();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user