Extend full bindless to cover cases with phi nodes

This commit is contained in:
Gabriel A 2024-05-23 01:53:34 -03:00
commit 3e9800cb81

View file

@ -64,15 +64,20 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
Operand nvHandle = texOp.GetSource(0); Operand nvHandle = texOp.GetSource(0);
if (nvHandle.AsgOp is not Operation handleOp || if (nvHandle.AsgOp is PhiNode phi)
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. for (int srcIndex = 0; srcIndex < phi.SourcesCount; srcIndex++)
// 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. Operand phiSource = phi.GetSource(srcIndex);
// It might be removed in the future, if we can mitigate the performance impact.
if (phiSource.AsgOp is not PhiNode && !IsBindlessAccessAllowed(phiSource))
{
return false;
}
}
}
else if (!IsBindlessAccessAllowed(nvHandle))
{
return false; return false;
} }
@ -130,6 +135,30 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
return true; return true;
} }
private static bool IsBindlessAccessAllowed(Operand nvHandle)
{
if (nvHandle.Type == OperandType.ConstantBuffer)
{
// Bindless access with handles from constant buffer is allowed.
return true;
}
if (nvHandle.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 true;
}
private static bool TryConvertBindless(BasicBlock block, ResourceManager resourceManager, IGpuAccessor gpuAccessor, TextureOperation texOp) private static bool TryConvertBindless(BasicBlock block, ResourceManager resourceManager, IGpuAccessor gpuAccessor, TextureOperation texOp)
{ {
if (texOp.Inst == Instruction.TextureSample || texOp.Inst.IsTextureQuery()) if (texOp.Inst == Instruction.TextureSample || texOp.Inst.IsTextureQuery())