aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen')
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs7
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs3
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs28
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs34
4 files changed, 66 insertions, 6 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
index 796eb441..6b02f2bf 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
@@ -184,8 +184,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
case Instruction.TextureSample:
return TextureSample(context, operation);
- case Instruction.TextureSize:
- return TextureSize(context, operation);
+ case Instruction.TextureQuerySamples:
+ return TextureQuerySamples(context, operation);
+
+ case Instruction.TextureQuerySize:
+ return TextureQuerySize(context, operation);
case Instruction.UnpackDouble2x32:
return UnpackDouble2x32(context, operation);
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
index eb194c20..5c2d16f4 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
@@ -118,7 +118,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.Subtract, InstType.OpBinary, "-", 2);
Add(Instruction.SwizzleAdd, InstType.CallTernary, HelperFunctionNames.SwizzleAdd);
Add(Instruction.TextureSample, InstType.Special);
- Add(Instruction.TextureSize, InstType.Special);
+ Add(Instruction.TextureQuerySamples, InstType.Special);
+ Add(Instruction.TextureQuerySize, InstType.Special);
Add(Instruction.Truncate, InstType.CallUnary, "trunc");
Add(Instruction.UnpackDouble2x32, InstType.Special);
Add(Instruction.UnpackHalf2x16, InstType.Special);
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index a1f92d11..7510e887 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -517,7 +517,33 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return texCall;
}
- public static string TextureSize(CodeGenContext context, AstOperation operation)
+ public static string TextureQuerySamples(CodeGenContext context, AstOperation operation)
+ {
+ AstTextureOperation texOp = (AstTextureOperation)operation;
+
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+
+ // TODO: Bindless texture support. For now we just return 0.
+ if (isBindless)
+ {
+ return NumberFormatter.FormatInt(0);
+ }
+
+ bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
+
+ string indexExpr = null;
+
+ if (isIndexed)
+ {
+ indexExpr = GetSoureExpr(context, texOp.GetSource(0), AggregateType.S32);
+ }
+
+ string samplerName = GetSamplerName(context.Properties, texOp, indexExpr);
+
+ return $"textureSamples({samplerName})";
+ }
+
+ public static string TextureQuerySize(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
index 719ccf0c..771723c2 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
@@ -134,7 +134,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
Add(Instruction.Subtract, GenerateSubtract);
Add(Instruction.SwizzleAdd, GenerateSwizzleAdd);
Add(Instruction.TextureSample, GenerateTextureSample);
- Add(Instruction.TextureSize, GenerateTextureSize);
+ Add(Instruction.TextureQuerySamples, GenerateTextureQuerySamples);
+ Add(Instruction.TextureQuerySize, GenerateTextureQuerySize);
Add(Instruction.Truncate, GenerateTruncate);
Add(Instruction.UnpackDouble2x32, GenerateUnpackDouble2x32);
Add(Instruction.UnpackHalf2x16, GenerateUnpackHalf2x16);
@@ -1492,7 +1493,36 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
return new OperationResult(swizzledResultType, result);
}
- private static OperationResult GenerateTextureSize(CodeGenContext context, AstOperation operation)
+ private static OperationResult GenerateTextureQuerySamples(CodeGenContext context, AstOperation operation)
+ {
+ AstTextureOperation texOp = (AstTextureOperation)operation;
+
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+
+ // TODO: Bindless texture support. For now we just return 0.
+ if (isBindless)
+ {
+ return new OperationResult(AggregateType.S32, context.Constant(context.TypeS32(), 0));
+ }
+
+ bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
+
+ if (isIndexed)
+ {
+ context.GetS32(texOp.GetSource(0));
+ }
+
+ (var imageType, var sampledImageType, var sampledImageVariable) = context.Samplers[texOp.Binding];
+
+ var image = context.Load(sampledImageType, sampledImageVariable);
+ image = context.Image(imageType, image);
+
+ SpvInstruction result = context.ImageQuerySamples(context.TypeS32(), image);
+
+ return new OperationResult(AggregateType.S32, result);
+ }
+
+ private static OperationResult GenerateTextureQuerySize(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;