コード例 #1
0
ファイル: NvGpuEngine3d.cs プロジェクト: tangyiyong/Ryujinx
 public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
 {
     if (Methods.TryGetValue(MethCall.Method, out NvGpuMethod Method))
     {
         Method(Vmm, MethCall);
     }
     else
     {
         WriteRegister(MethCall);
     }
 }
コード例 #2
0
ファイル: NvGpuEngine3d.cs プロジェクト: tangyiyong/Ryujinx
        private void CbData(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress);

            int Offset = ReadRegister(NvGpuEngine3dReg.ConstBufferOffset);

            Vmm.WriteInt32(Position + Offset, MethCall.Argument);

            WriteRegister(NvGpuEngine3dReg.ConstBufferOffset, Offset + 4);

            Gpu.ResourceManager.ClearPbCache(NvGpuBufferType.ConstBuffer);
        }
コード例 #3
0
ファイル: NvGpuFifo.cs プロジェクト: zhubaojian/Ryujinx
        public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            if ((NvGpuFifoMeth)MethCall.Method == NvGpuFifoMeth.BindChannel)
            {
                NvGpuEngine Engine = (NvGpuEngine)MethCall.Argument;

                SubChannels[MethCall.SubChannel] = Engine;
            }
            else
            {
                switch (SubChannels[MethCall.SubChannel])
                {
                    case NvGpuEngine._2d:  Call2dMethod  (Vmm, MethCall); break;
                    case NvGpuEngine._3d:  Call3dMethod  (Vmm, MethCall); break;
                    case NvGpuEngine.P2mf: CallP2mfMethod(Vmm, MethCall); break;
                    case NvGpuEngine.M2mf: CallM2mfMethod(Vmm, MethCall); break;
                }
            }
        }
コード例 #4
0
ファイル: NvGpuEngineP2mf.cs プロジェクト: zhubaojian/Ryujinx
        private void PushData(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            if (Buffer == null)
            {
                return;
            }

            for (int Shift = 0; Shift < 32 && CopyOffset < CopySize; Shift += 8, CopyOffset++)
            {
                Buffer[CopyOffset] = (byte)(MethCall.Argument >> Shift);
            }

            if (MethCall.IsLastCall)
            {
                if (CopyLinear)
                {
                    Vmm.WriteBytes(CopyAddress, Buffer);
                }
                else
                {
                    BlockLinearSwizzle Swizzle = new BlockLinearSwizzle(CopyWidth, 1, CopyGobBlockHeight);

                    int SrcOffset = 0;

                    for (int Y = CopyStartY; Y < CopyHeight && SrcOffset < CopySize; Y++)
                    {
                        for (int X = CopyStartX; X < CopyWidth && SrcOffset < CopySize; X++)
                        {
                            int DstOffset = Swizzle.GetSwizzleOffset(X, Y);

                            Vmm.WriteByte(CopyAddress + DstOffset, Buffer[SrcOffset++]);
                        }
                    }
                }

                Buffer = null;
            }
        }
コード例 #5
0
ファイル: NvGpuEngineP2mf.cs プロジェクト: zhubaojian/Ryujinx
        private void Execute(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            //TODO: Some registers and copy modes are still not implemented.
            int Control = MethCall.Argument;

            long DstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress);

            int DstPitch  = ReadRegister(NvGpuEngineP2mfReg.DstPitch);
            int DstBlkDim = ReadRegister(NvGpuEngineP2mfReg.DstBlockDim);

            int DstX = ReadRegister(NvGpuEngineP2mfReg.DstX);
            int DstY = ReadRegister(NvGpuEngineP2mfReg.DstY);

            int DstWidth  = ReadRegister(NvGpuEngineP2mfReg.DstWidth);
            int DstHeight = ReadRegister(NvGpuEngineP2mfReg.DstHeight);

            int LineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn);
            int LineCount    = ReadRegister(NvGpuEngineP2mfReg.LineCount);

            CopyLinear = (Control & 1) != 0;

            CopyGobBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);

            CopyStartX = DstX;
            CopyStartY = DstY;

            CopyWidth  = DstWidth;
            CopyHeight = DstHeight;

            CopyAddress = DstAddress;

            CopyOffset = 0;
            CopySize   = LineLengthIn * LineCount;

            Buffer = new byte[CopySize];
        }
コード例 #6
0
ファイル: NvGpuEngine3d.cs プロジェクト: tangyiyong/Ryujinx
        private void VertexEndGl(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            LockCaches();

            GalPipelineState State = new GalPipelineState();

            SetFrameBuffer(State);
            SetFrontFace(State);
            SetCullFace(State);
            SetDepth(State);
            SetStencil(State);
            SetBlending(State);
            SetColorMask(State);
            SetPrimitiveRestart(State);

            for (int FbIndex = 0; FbIndex < 8; FbIndex++)
            {
                SetFrameBuffer(Vmm, FbIndex);
            }

            SetZeta(Vmm);

            SetRenderTargets();

            long[] Keys = UploadShaders(Vmm);

            Gpu.Renderer.Shader.BindProgram();

            UploadTextures(Vmm, State, Keys);
            UploadConstBuffers(Vmm, State, Keys);
            UploadVertexArrays(Vmm, State);

            DispatchRender(Vmm, State);

            UnlockCaches();
        }
コード例 #7
0
 private void WriteRegister(GpuMethodCall MethCall)
 {
     Registers[MethCall.Method] = MethCall.Argument;
 }
コード例 #8
0
ファイル: NvGpuFifo.cs プロジェクト: zhubaojian/Ryujinx
 private void Call2dMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
 {
     Gpu.Engine2d.CallMethod(Vmm, MethCall);
 }
コード例 #9
0
ファイル: NvGpuFifo.cs プロジェクト: zhubaojian/Ryujinx
 private void CallM2mfMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
 {
     Gpu.EngineM2mf.CallMethod(Vmm, MethCall);
 }
コード例 #10
0
ファイル: NvGpuFifo.cs プロジェクト: zhubaojian/Ryujinx
        private void Call3dMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            if (MethCall.Method < 0x80)
            {
                switch ((NvGpuFifoMeth)MethCall.Method)
                {
                    case NvGpuFifoMeth.SetMacroUploadAddress:
                    {
                        CurrMacroPosition = MethCall.Argument;

                        break;
                    }

                    case NvGpuFifoMeth.SendMacroCodeData:
                    {
                        Mme[CurrMacroPosition++] = MethCall.Argument;

                        break;
                    }

                    case NvGpuFifoMeth.SetMacroBindingIndex:
                    {
                        CurrMacroBindIndex = MethCall.Argument;

                        break;
                    }

                    case NvGpuFifoMeth.BindMacro:
                    {
                        int Position = MethCall.Argument;

                        Macros[CurrMacroBindIndex] = new CachedMacro(this, Gpu.Engine3d, Position);

                        break;
                    }

                    default: CallP2mfMethod(Vmm, MethCall); break;
                }
            }
            else if (MethCall.Method < 0xe00)
            {
                Gpu.Engine3d.CallMethod(Vmm, MethCall);
            }
            else
            {
                int MacroIndex = (MethCall.Method >> 1) & MacroIndexMask;

                if ((MethCall.Method & 1) != 0)
                {
                    Macros[MacroIndex].PushArgument(MethCall.Argument);
                }
                else
                {
                    Macros[MacroIndex].StartExecution(MethCall.Argument);
                }

                if (MethCall.IsLastCall)
                {
                    Macros[MacroIndex].Execute(Vmm, Mme);
                }
            }
        }
コード例 #11
0
ファイル: NvGpuEngineM2mf.cs プロジェクト: zhubaojian/Ryujinx
        private void Execute(NvGpuVmm Vmm, GpuMethodCall MethCall)
        {
            //TODO: Some registers and copy modes are still not implemented.
            int Control = MethCall.Argument;

            bool SrcLinear = ((Control >> 7) & 1) != 0;
            bool DstLinear = ((Control >> 8) & 1) != 0;
            bool Copy2d    = ((Control >> 9) & 1) != 0;

            long SrcAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.SrcAddress);
            long DstAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.DstAddress);

            int SrcPitch = ReadRegister(NvGpuEngineM2mfReg.SrcPitch);
            int DstPitch = ReadRegister(NvGpuEngineM2mfReg.DstPitch);

            int XCount = ReadRegister(NvGpuEngineM2mfReg.XCount);
            int YCount = ReadRegister(NvGpuEngineM2mfReg.YCount);

            int Swizzle = ReadRegister(NvGpuEngineM2mfReg.Swizzle);

            int DstBlkDim = ReadRegister(NvGpuEngineM2mfReg.DstBlkDim);
            int DstSizeX  = ReadRegister(NvGpuEngineM2mfReg.DstSizeX);
            int DstSizeY  = ReadRegister(NvGpuEngineM2mfReg.DstSizeY);
            int DstSizeZ  = ReadRegister(NvGpuEngineM2mfReg.DstSizeZ);
            int DstPosXY  = ReadRegister(NvGpuEngineM2mfReg.DstPosXY);
            int DstPosZ   = ReadRegister(NvGpuEngineM2mfReg.DstPosZ);

            int SrcBlkDim = ReadRegister(NvGpuEngineM2mfReg.SrcBlkDim);
            int SrcSizeX  = ReadRegister(NvGpuEngineM2mfReg.SrcSizeX);
            int SrcSizeY  = ReadRegister(NvGpuEngineM2mfReg.SrcSizeY);
            int SrcSizeZ  = ReadRegister(NvGpuEngineM2mfReg.SrcSizeZ);
            int SrcPosXY  = ReadRegister(NvGpuEngineM2mfReg.SrcPosXY);
            int SrcPosZ   = ReadRegister(NvGpuEngineM2mfReg.SrcPosZ);

            int SrcCpp = ((Swizzle >> 20) & 7) + 1;
            int DstCpp = ((Swizzle >> 24) & 7) + 1;

            int DstPosX = (DstPosXY >> 0) & 0xffff;
            int DstPosY = (DstPosXY >> 16) & 0xffff;

            int SrcPosX = (SrcPosXY >> 0) & 0xffff;
            int SrcPosY = (SrcPosXY >> 16) & 0xffff;

            int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf);
            int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);

            long SrcPA = Vmm.GetPhysicalAddress(SrcAddress);
            long DstPA = Vmm.GetPhysicalAddress(DstAddress);

            if (Copy2d)
            {
                if (SrcLinear)
                {
                    SrcPosX = SrcPosY = SrcPosZ = 0;
                }

                if (DstLinear)
                {
                    DstPosX = DstPosY = DstPosZ = 0;
                }

                if (SrcLinear && DstLinear)
                {
                    for (int Y = 0; Y < YCount; Y++)
                    {
                        int SrcOffset = (SrcPosY + Y) * SrcPitch + SrcPosX * SrcCpp;
                        int DstOffset = (DstPosY + Y) * DstPitch + DstPosX * DstCpp;

                        long Src = SrcPA + (uint)SrcOffset;
                        long Dst = DstPA + (uint)DstOffset;

                        Vmm.Memory.CopyBytes(Src, Dst, XCount * SrcCpp);
                    }
                }
                else
                {
                    ISwizzle SrcSwizzle;

                    if (SrcLinear)
                    {
                        SrcSwizzle = new LinearSwizzle(SrcPitch, SrcCpp);
                    }
                    else
                    {
                        SrcSwizzle = new BlockLinearSwizzle(SrcSizeX, SrcCpp, SrcBlockHeight);
                    }

                    ISwizzle DstSwizzle;

                    if (DstLinear)
                    {
                        DstSwizzle = new LinearSwizzle(DstPitch, DstCpp);
                    }
                    else
                    {
                        DstSwizzle = new BlockLinearSwizzle(DstSizeX, DstCpp, DstBlockHeight);
                    }

                    for (int Y = 0; Y < YCount; Y++)
                    {
                        for (int X = 0; X < XCount; X++)
                        {
                            int SrcOffset = SrcSwizzle.GetSwizzleOffset(SrcPosX + X, SrcPosY + Y);
                            int DstOffset = DstSwizzle.GetSwizzleOffset(DstPosX + X, DstPosY + Y);

                            long Src = SrcPA + (uint)SrcOffset;
                            long Dst = DstPA + (uint)DstOffset;

                            Vmm.Memory.CopyBytes(Src, Dst, SrcCpp);
                        }
                    }
                }
            }
            else
            {
                Vmm.Memory.CopyBytes(SrcPA, DstPA, XCount);
            }
        }