Compare commits

...

2 Commits

Author SHA1 Message Date
gdkchan
0ef0fc044a Small graphics abstraction layer cleanup (#3257) 2022-04-04 18:21:06 -03:00
gdkchan
04bd87ed5a Fix shader textureSize with multisample and buffer textures (#3240)
* Fix shader textureSize with multisample and buffer textures

* Replace out param with tuple return value
2022-04-04 14:43:58 -03:00
5 changed files with 38 additions and 60 deletions

View File

@@ -1,47 +0,0 @@
namespace Ryujinx.Graphics.GAL
{
public struct DepthStencilState
{
public bool DepthTestEnable { get; }
public bool DepthWriteEnable { get; }
public bool StencilTestEnable { get; }
public CompareOp DepthFunc { get; }
public CompareOp StencilFrontFunc { get; }
public StencilOp StencilFrontSFail { get; }
public StencilOp StencilFrontDpPass { get; }
public StencilOp StencilFrontDpFail { get; }
public CompareOp StencilBackFunc { get; }
public StencilOp StencilBackSFail { get; }
public StencilOp StencilBackDpPass { get; }
public StencilOp StencilBackDpFail { get; }
public DepthStencilState(
bool depthTestEnable,
bool depthWriteEnable,
bool stencilTestEnable,
CompareOp depthFunc,
CompareOp stencilFrontFunc,
StencilOp stencilFrontSFail,
StencilOp stencilFrontDpPass,
StencilOp stencilFrontDpFail,
CompareOp stencilBackFunc,
StencilOp stencilBackSFail,
StencilOp stencilBackDpPass,
StencilOp stencilBackDpFail)
{
DepthTestEnable = depthTestEnable;
DepthWriteEnable = depthWriteEnable;
StencilTestEnable = stencilTestEnable;
DepthFunc = depthFunc;
StencilFrontFunc = stencilFrontFunc;
StencilFrontSFail = stencilFrontSFail;
StencilFrontDpPass = stencilFrontDpPass;
StencilFrontDpFail = stencilFrontDpFail;
StencilBackFunc = stencilBackFunc;
StencilBackSFail = stencilBackSFail;
StencilBackDpPass = stencilBackDpPass;
StencilBackDpFail = stencilBackDpFail;
}
}
}

View File

@@ -9,7 +9,6 @@ namespace Ryujinx.Graphics.GAL
Texture2DArray, Texture2DArray,
Texture2DMultisample, Texture2DMultisample,
Texture2DMultisampleArray, Texture2DMultisampleArray,
Rectangle,
Cubemap, Cubemap,
CubemapArray, CubemapArray,
TextureBuffer TextureBuffer

View File

@@ -444,8 +444,8 @@ namespace Ryujinx.Graphics.OpenGL
return TextureTarget.Texture2DArray; return TextureTarget.Texture2DArray;
case Target.Texture2DMultisample: case Target.Texture2DMultisample:
return TextureTarget.Texture2DMultisample; return TextureTarget.Texture2DMultisample;
case Target.Rectangle: case Target.Texture2DMultisampleArray:
return TextureTarget.TextureRectangle; return TextureTarget.Texture2DMultisampleArray;
case Target.Cubemap: case Target.Cubemap:
return TextureTarget.TextureCubeMap; return TextureTarget.TextureCubeMap;
case Target.CubemapArray: case Target.CubemapArray:

View File

@@ -70,6 +70,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
AppendLine("}" + suffix); AppendLine("}" + suffix);
} }
public (TextureDescriptor, int) FindTextureDescriptor(AstTextureOperation texOp)
{
TextureDescriptor[] descriptors = Config.GetTextureDescriptors();
for (int i = 0; i < descriptors.Length; i++)
{
var descriptor = descriptors[i];
if (descriptor.CbufSlot == texOp.CbufSlot &&
descriptor.HandleIndex == texOp.Handle &&
descriptor.Format == texOp.Format)
{
return (descriptor, i);
}
}
return (default, -1);
}
private static int FindDescriptorIndex(TextureDescriptor[] array, AstTextureOperation texOp) private static int FindDescriptorIndex(TextureDescriptor[] array, AstTextureOperation texOp)
{ {
for (int i = 0; i < array.Length; i++) for (int i = 0; i < array.Length; i++)

View File

@@ -756,27 +756,34 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
int lodSrcIndex = isBindless || isIndexed ? 1 : 0;
IAstNode lod = operation.GetSource(lodSrcIndex);
string lodExpr = GetSoureExpr(context, lod, GetSrcVarType(operation.Inst, lodSrcIndex));
if (texOp.Index == 3) if (texOp.Index == 3)
{ {
return $"textureQueryLevels({samplerName})"; return $"textureQueryLevels({samplerName})";
} }
else else
{ {
string texCall = $"textureSize({samplerName}, {lodExpr}){GetMask(texOp.Index)}"; (TextureDescriptor descriptor, int descriptorIndex) = context.FindTextureDescriptor(texOp);
bool hasLod = !descriptor.Type.HasFlag(SamplerType.Multisample) && descriptor.Type != SamplerType.TextureBuffer;
string texCall;
if (hasLod)
{
int lodSrcIndex = isBindless || isIndexed ? 1 : 0;
IAstNode lod = operation.GetSource(lodSrcIndex);
string lodExpr = GetSoureExpr(context, lod, GetSrcVarType(operation.Inst, lodSrcIndex));
texCall = $"textureSize({samplerName}, {lodExpr}){GetMask(texOp.Index)}";
}
else
{
texCall = $"textureSize({samplerName}){GetMask(texOp.Index)}";
}
if (context.Config.Stage.SupportsRenderScale() && if (context.Config.Stage.SupportsRenderScale() &&
!isBindless && !isBindless &&
!isIndexed) !isIndexed)
{ {
int index = context.FindTextureDescriptorIndex(texOp); texCall = $"Helper_TextureSizeUnscale({texCall}, {descriptorIndex})";
texCall = "Helper_TextureSizeUnscale(" + texCall + ", " + index + ")";
} }
return texCall; return texCall;