Skip to content

SPIR-V: use the declared image type for size and level queries - #662

Open
aldotms89 wants to merge 1 commit into
igawa6:mainfrom
aldotms89:xlate-image-size-query
Open

aldotms89 wants to merge 1 commit into
igawa6:mainfrom
aldotms89:xlate-image-size-query

Conversation

@aldotms89

Copy link
Copy Markdown

What and why

Separate descriptors are declared as plain images, so a query must load an OpTypeImage directly. Combined descriptors still require their sampled-image load followed by OpImage. The query retains the correct LOD operand after any indexed handles. The branch carries synthetic tests and the reference entry. The companion source patch xlate-image-size-query.patch applies to main and is provided for the maintainer’s documented Ryujinx version update.

Checked

  • PC Python and SPIRV-Tools: all 8 synthetic tests passed against a fresh translator built from current main plus the C# patch.
  • PC documentation: all 11 checks passed.
  • Phone runs on the test app: none on this branch.
  • GPU drivers: no new system-driver or Turnip run.

Docs

  • Added the separate-image query reference entry and regenerated the symptom index.
  • The maintainer will regenerate the translator chain version and headers when updating the vendored translator.
  • No game files, keys, or extracted game bytes in the change or attachments.
  • Source and metadata only. No binaries, vendored files, or chain version files in the branch.

Shader impact report

These measurements are from the earlier PC comparison with the same profile and Vulkan finishing passes on each side. This port did not rebuild the game libraries.

Game Coverage Result
Hyrule Warriors: Definitive Edition Full library, 1,004 keys All 1,033 modules byte-identical
Resident Evil 6 Every 25th key plus paired pixel keys, 3,213 keys All 3,340 modules byte-identical
World War Z Full v458752 library All 44,000 previously built entry hashes matched. 40 missing compute keys were restored, adding 48 validated module variants.

The original WWZ failures reported an OpLoad result type that differed from the pointer type. The restored compute variants passed Vulkan 1.3 validation. The maintainer should regenerate the official chain and publish the WWZ delta as an opt-in shader update.

Translator source patch (dm/third_party/ryujinx is not vendored in this repo)
diff --git a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs
index bfb85ac5..c41951e1 100644
--- a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs
+++ b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs
@@ -285,4 +285,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
                     sampledImagePointerType,
                     sampledImageVariable,
+                    sampler.Separate, // PEANUTS: descriptor type for image queries
                     sampler.ArrayLength != 1,
                     sampler.ArrayLength > 1 && sampler.ArrayLength <= SamplerDeclaration.ShaderIndexedMaxLength)); // PEANUTS: IsShaderIndexed
diff --git a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
index 0399a5bf..6e9fc233 100644
--- a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
+++ b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
@@ -1710,7 +1710,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
 
             SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()];
-            SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
-
-            image = context.Image(declaration.ImageType, image);
+            // PEANUTS: size and level queries use the image directly for a separate descriptor.
+            SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex, imageOnly: declaration.IsSeparate);
+            if (!declaration.IsSeparate)
+            {
+                image = context.Image(declaration.ImageType, image);
+            }
 
             if (texOp.Index == 3)
@@ -2448,5 +2451,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
         }
 
-        private static SpvInstruction GenerateSampledImageLoad(CodeGenContext context, AstTextureOperation texOp, SamplerDeclaration declaration, ref int srcIndex)
+        private static SpvInstruction GenerateSampledImageLoad(CodeGenContext context, AstTextureOperation texOp, SamplerDeclaration declaration, ref int srcIndex, bool imageOnly = false)
         {
             SpvInstruction image = declaration.Image;
@@ -2461,5 +2464,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
             }
 
-            if (texOp.IsSeparate)
+            if (texOp.IsSeparate || imageOnly)
             {
                 image = context.Load(declaration.ImageType, image);
@@ -2469,4 +2472,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
                 }
 
+                if (imageOnly)
+                {
+                    // Array lowering inserts the sampler index before the query's LOD.
+                    if (texOp.IsSeparate && context.Samplers[texOp.GetSamplerSetAndBinding()].IsIndexed)
+                    {
+                        srcIndex++;
+                    }
+
+                    return image;
+                }
+
                 SamplerDeclaration samplerDeclaration = context.Samplers[texOp.GetSamplerSetAndBinding()];
 
diff --git a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SamplerDeclaration.cs b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SamplerDeclaration.cs
index d6782824..d7a9b009 100644
--- a/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SamplerDeclaration.cs
+++ b/dm/third_party/ryujinx/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/SamplerDeclaration.cs
@@ -9,4 +9,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
         public readonly Instruction SampledImagePointerType;
         public readonly Instruction Image;
+        public readonly bool IsSeparate; // PEANUTS: descriptor type for image queries
         public readonly bool IsIndexed;
         // PEANUTS: an array the shader indexes with a value it computes (an array of handles from a buffer, BindlessToArray: at most 256 elements; the pools of
@@ -21,4 +22,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
             Instruction sampledImagePointerType,
             Instruction image,
+            bool isSeparate,
             bool isIndexed,
             bool isShaderIndexed = false) // PEANUTS
@@ -28,4 +30,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
             SampledImagePointerType = sampledImagePointerType;
             Image = image;
+            IsSeparate = isSeparate;
             IsIndexed = isIndexed;
             IsShaderIndexed = isShaderIndexed; // PEANUTS

A separate image descriptor supplies a plain image to a size or level query. Add synthetic coverage and document the translator change for the maintainer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant