mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-08-05 17:58:28 +02:00
Delete ShaderConfig and organize shader resources/definitions better (#5509)
* Move some properties out of ShaderConfig * Stop using ShaderConfig on backends * Replace ShaderConfig usages on Translator and passes * Move remaining properties out of ShaderConfig and delete ShaderConfig * Remove ResourceManager property from TranslatorContext * Move Rewriter passes to separate transform pass files * Fix TransformPasses.RunPass on cases where a node is removed * Move remaining ClipDistancePrimitivesWritten and UsedFeatures updates to decode stage * Reduce excessive parameter passing a bit by using structs more * Remove binding parameter from ShaderProperties methods since it is redundant * Replace decoder instruction checks with switch statement * Put GLSL on the same plan as SPIR-V for input/output declaration * Stop mutating TranslatorContext state when Translate is called * Pass most of the graphics state using a struct instead of individual query methods * Auto-format * Auto-format * Add backend logging interface * Auto-format * Remove unnecessary use of interpolated strings * Remove more modifications of AttributeUsage after decode * PR feedback * gl_Layer is not supported on compute
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
|
||||
// Some of those attributes are per invocation,
|
||||
// so we should ignore any primitive vertex indexing for those.
|
||||
bool hasPrimitiveVertex = AttributeMap.HasPrimitiveVertex(context.Config.Stage, op.O) && !op.P;
|
||||
bool hasPrimitiveVertex = AttributeMap.HasPrimitiveVertex(context.TranslatorContext.Definitions.Stage, op.O) && !op.P;
|
||||
|
||||
if (!op.Phys)
|
||||
{
|
||||
@@ -52,10 +52,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
}
|
||||
else if (op.SrcB == RegisterConsts.RegisterZeroIndex || op.P)
|
||||
{
|
||||
int offset = FixedFuncToUserAttribute(context.Config, op.Imm11 + index * 4, op.O);
|
||||
|
||||
context.FlagAttributeRead(offset);
|
||||
|
||||
int offset = FixedFuncToUserAttribute(context.TranslatorContext, op.Imm11 + index * 4, op.O);
|
||||
bool isOutput = op.O && CanLoadOutput(offset);
|
||||
|
||||
if (!op.P && !isOutput && TryConvertIdToIndexForVulkan(context, offset, out Operand value))
|
||||
@@ -69,10 +66,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = FixedFuncToUserAttribute(context.Config, op.Imm11 + index * 4, op.O);
|
||||
|
||||
context.FlagAttributeRead(offset);
|
||||
|
||||
int offset = FixedFuncToUserAttribute(context.TranslatorContext, op.Imm11 + index * 4, op.O);
|
||||
bool isOutput = op.O && CanLoadOutput(offset);
|
||||
|
||||
context.Copy(Register(rd), AttributeMap.GenerateAttributeLoad(context, primVertex, offset, isOutput, false));
|
||||
@@ -98,7 +92,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
Operand offset = context.ISubtract(GetSrcReg(context, op.SrcA), Const(AttributeConsts.UserAttributeBase));
|
||||
Operand vecIndex = context.ShiftRightU32(offset, Const(4));
|
||||
Operand elemIndex = context.BitwiseAnd(context.ShiftRightU32(offset, Const(2)), Const(3));
|
||||
Operand invocationId = AttributeMap.HasInvocationId(context.Config.Stage, isOutput: true)
|
||||
Operand invocationId = AttributeMap.HasInvocationId(context.TranslatorContext.Definitions.Stage, isOutput: true)
|
||||
? context.Load(StorageKind.Input, IoVariable.InvocationId)
|
||||
: null;
|
||||
|
||||
@@ -110,15 +104,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
|
||||
int offset = op.Imm11 + index * 4;
|
||||
|
||||
if (!context.Config.IsUsedOutputAttribute(offset))
|
||||
if (!context.TranslatorContext.AttributeUsage.IsUsedOutputAttribute(offset))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
offset = FixedFuncToUserAttribute(context.Config, offset, isOutput: true);
|
||||
|
||||
context.FlagAttributeWritten(offset);
|
||||
|
||||
offset = FixedFuncToUserAttribute(context.TranslatorContext, offset, isOutput: true);
|
||||
AttributeMap.GenerateAttributeStore(context, offset, op.P, Register(rd));
|
||||
}
|
||||
}
|
||||
@@ -128,8 +119,6 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
{
|
||||
InstIpa op = context.GetOp<InstIpa>();
|
||||
|
||||
context.FlagAttributeRead(op.Imm10);
|
||||
|
||||
Operand res;
|
||||
|
||||
bool isFixedFunc = false;
|
||||
@@ -151,7 +140,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
{
|
||||
int index = (op.Imm10 - AttributeConsts.UserAttributeBase) >> 4;
|
||||
|
||||
if (context.Config.ImapTypes[index].GetFirstUsedType() == PixelImap.Perspective)
|
||||
if (context.TranslatorContext.Definitions.ImapTypes[index].GetFirstUsedType() == PixelImap.Perspective)
|
||||
{
|
||||
res = context.FPMultiply(res, context.Load(StorageKind.Input, IoVariable.FragmentCoord, null, Const(3)));
|
||||
}
|
||||
@@ -162,11 +151,11 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
// because the shader code is not expecting scaled values.
|
||||
res = context.FPDivide(res, context.Load(StorageKind.ConstantBuffer, SupportBuffer.Binding, Const((int)SupportBufferField.RenderScale), Const(0)));
|
||||
|
||||
if (op.Imm10 == AttributeConsts.PositionY && context.Config.Options.TargetApi != TargetApi.OpenGL)
|
||||
if (op.Imm10 == AttributeConsts.PositionY && context.TranslatorContext.Options.TargetApi != TargetApi.OpenGL)
|
||||
{
|
||||
// If YNegate is enabled, we need to flip the fragment coordinates vertically, unless
|
||||
// the API supports changing the origin (only OpenGL does).
|
||||
if (context.Config.GpuAccessor.QueryYNegateEnabled())
|
||||
if (context.TranslatorContext.Definitions.YNegateEnabled)
|
||||
{
|
||||
Operand viewportHeight = context.Load(StorageKind.ConstantBuffer, 0, Const((int)SupportBufferField.ViewportSize), Const(1));
|
||||
|
||||
@@ -174,7 +163,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (op.Imm10 == AttributeConsts.FrontFacing && context.Config.GpuAccessor.QueryHostHasFrontFacingBug())
|
||||
else if (op.Imm10 == AttributeConsts.FrontFacing && context.TranslatorContext.GpuAccessor.QueryHostHasFrontFacingBug())
|
||||
{
|
||||
// gl_FrontFacing sometimes has incorrect (flipped) values depending how it is accessed on Intel GPUs.
|
||||
// This weird trick makes it behave.
|
||||
@@ -231,12 +220,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
{
|
||||
if (!(emit || cut))
|
||||
{
|
||||
context.Config.GpuAccessor.Log("Invalid OUT encoding.");
|
||||
context.TranslatorContext.GpuAccessor.Log("Invalid OUT encoding.");
|
||||
}
|
||||
|
||||
if (emit)
|
||||
{
|
||||
if (context.Config.LastInVertexPipeline)
|
||||
if (context.TranslatorContext.Definitions.LastInVertexPipeline)
|
||||
{
|
||||
context.PrepareForVertexReturn(out var tempXLocal, out var tempYLocal, out var tempZLocal);
|
||||
|
||||
@@ -289,13 +278,13 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
{
|
||||
// TODO: If two sided rendering is enabled, then this should return
|
||||
// FrontColor if the fragment is front facing, and back color otherwise.
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.Config, attr, isOutput: false));
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.TranslatorContext, attr, isOutput: false));
|
||||
return true;
|
||||
}
|
||||
else if (attr == AttributeConsts.FogCoord)
|
||||
{
|
||||
// TODO: We likely need to emulate the fixed-function functionality for FogCoord here.
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.Config, attr, isOutput: false));
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.TranslatorContext, attr, isOutput: false));
|
||||
return true;
|
||||
}
|
||||
else if (attr >= AttributeConsts.BackColorDiffuseR && attr < AttributeConsts.ClipDistance0)
|
||||
@@ -305,7 +294,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
}
|
||||
else if (attr >= AttributeConsts.TexCoordBase && attr < AttributeConsts.TexCoordEnd)
|
||||
{
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.Config, attr, isOutput: false));
|
||||
selectedAttr = GenerateIpaLoad(context, FixedFuncToUserAttribute(context.TranslatorContext, attr, isOutput: false));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -318,53 +307,44 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
return AttributeMap.GenerateAttributeLoad(context, null, offset, isOutput: false, isPerPatch: false);
|
||||
}
|
||||
|
||||
private static int FixedFuncToUserAttribute(ShaderConfig config, int attr, bool isOutput)
|
||||
private static int FixedFuncToUserAttribute(TranslatorContext translatorContext, int attr, bool isOutput)
|
||||
{
|
||||
bool supportsLayerFromVertexOrTess = config.GpuAccessor.QueryHostSupportsLayerVertexTessellation();
|
||||
bool supportsLayerFromVertexOrTess = translatorContext.GpuAccessor.QueryHostSupportsLayerVertexTessellation();
|
||||
int fixedStartAttr = supportsLayerFromVertexOrTess ? 0 : 1;
|
||||
|
||||
if (attr == AttributeConsts.Layer && config.Stage != ShaderStage.Geometry && !supportsLayerFromVertexOrTess)
|
||||
if (attr == AttributeConsts.Layer && translatorContext.Definitions.Stage != ShaderStage.Geometry && !supportsLayerFromVertexOrTess)
|
||||
{
|
||||
attr = FixedFuncToUserAttribute(config, attr, AttributeConsts.Layer, 0, isOutput);
|
||||
config.SetLayerOutputAttribute(attr);
|
||||
attr = FixedFuncToUserAttribute(translatorContext, attr, AttributeConsts.Layer, 0, isOutput);
|
||||
translatorContext.SetLayerOutputAttribute(attr);
|
||||
}
|
||||
else if (attr == AttributeConsts.FogCoord)
|
||||
{
|
||||
attr = FixedFuncToUserAttribute(config, attr, AttributeConsts.FogCoord, fixedStartAttr, isOutput);
|
||||
attr = FixedFuncToUserAttribute(translatorContext, attr, AttributeConsts.FogCoord, fixedStartAttr, isOutput);
|
||||
}
|
||||
else if (attr >= AttributeConsts.FrontColorDiffuseR && attr < AttributeConsts.ClipDistance0)
|
||||
{
|
||||
attr = FixedFuncToUserAttribute(config, attr, AttributeConsts.FrontColorDiffuseR, fixedStartAttr + 1, isOutput);
|
||||
attr = FixedFuncToUserAttribute(translatorContext, attr, AttributeConsts.FrontColorDiffuseR, fixedStartAttr + 1, isOutput);
|
||||
}
|
||||
else if (attr >= AttributeConsts.TexCoordBase && attr < AttributeConsts.TexCoordEnd)
|
||||
{
|
||||
attr = FixedFuncToUserAttribute(config, attr, AttributeConsts.TexCoordBase, fixedStartAttr + 5, isOutput);
|
||||
attr = FixedFuncToUserAttribute(translatorContext, attr, AttributeConsts.TexCoordBase, fixedStartAttr + 5, isOutput);
|
||||
}
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static int FixedFuncToUserAttribute(ShaderConfig config, int attr, int baseAttr, int baseIndex, bool isOutput)
|
||||
private static int FixedFuncToUserAttribute(TranslatorContext translatorContext, int attr, int baseAttr, int baseIndex, bool isOutput)
|
||||
{
|
||||
int index = (attr - baseAttr) >> 4;
|
||||
int userAttrIndex = config.GetFreeUserAttribute(isOutput, baseIndex + index);
|
||||
int userAttrIndex = translatorContext.AttributeUsage.GetFreeUserAttribute(isOutput, baseIndex + index);
|
||||
|
||||
if ((uint)userAttrIndex < Constants.MaxAttributes)
|
||||
{
|
||||
attr = AttributeConsts.UserAttributeBase + userAttrIndex * 16 + (attr & 0xf);
|
||||
|
||||
if (isOutput)
|
||||
{
|
||||
config.SetOutputUserAttributeFixedFunc(userAttrIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
config.SetInputUserAttributeFixedFunc(userAttrIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
config.GpuAccessor.Log($"No enough user attributes for fixed attribute offset 0x{attr:X}.");
|
||||
translatorContext.GpuAccessor.Log($"No enough user attributes for fixed attribute offset 0x{attr:X}.");
|
||||
}
|
||||
|
||||
return attr;
|
||||
@@ -372,7 +352,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
|
||||
private static bool TryConvertIdToIndexForVulkan(EmitterContext context, int attr, out Operand value)
|
||||
{
|
||||
if (context.Config.Options.TargetApi == TargetApi.Vulkan)
|
||||
if (context.TranslatorContext.Options.TargetApi == TargetApi.Vulkan)
|
||||
{
|
||||
if (attr == AttributeConsts.InstanceId)
|
||||
{
|
||||
|
Reference in New Issue
Block a user