From b066cfc1a3e31bf7197ddbd0f4d774b886cd9d65 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 12 Oct 2020 21:40:50 -0300 Subject: Add support for shader constant buffer slot indexing (#1608) * Add support for shader constant buffer slot indexing * Fix typo --- .../StructuredIr/StructuredProgram.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs') diff --git a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs index f1dd08f2..65de5218 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs @@ -2,6 +2,7 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation; using Ryujinx.Graphics.Shader.Translation; using System; using System.Collections.Generic; +using System.Numerics; namespace Ryujinx.Graphics.Shader.StructuredIr { @@ -73,12 +74,24 @@ namespace Ryujinx.Graphics.Shader.StructuredIr { Operand slot = operation.GetSource(0); - if (slot.Type != OperandType.Constant) + if (slot.Type == OperandType.Constant) { - throw new InvalidOperationException("Found load with non-constant constant buffer slot."); + context.Info.CBuffers.Add(slot.Value); } + else + { + // If the value is not constant, then we don't know + // how many constant buffers are used, so we assume + // all of them are used. + int cbCount = 32 - BitOperations.LeadingZeroCount(context.Config.GpuAccessor.QueryConstantBufferUse()); + + for (int index = 0; index < cbCount; index++) + { + context.Info.CBuffers.Add(index); + } - context.Info.CBuffers.Add(slot.Value); + context.Info.UsesCbIndexing = true; + } } else if (UsesStorage(inst)) { -- cgit v1.2.3