Exemple #1
0
        private void RefreshUsedConsts(GPUShader shader, GPUStateCapture state, ListView view)
        {
            view.BeginUpdate();
            view.Items.Clear();

            foreach (UInt32 baseRegIndex in shader.UsedRegisters)
            {
                var item = new ListViewItem();
                item.Text = baseRegIndex.ToString();

                var stateRegOffset = baseRegIndex + (shader.PixelShader ? 256U : 0);
                var stateRegIndex  = (UInt32)GPURegisterName.SHADER_CONSTANT_000_X + (4 * stateRegOffset);

                var varR = GPUExecutor.ToFloat(state.Reg(stateRegIndex + 0));
                var varG = GPUExecutor.ToFloat(state.Reg(stateRegIndex + 1));
                var varB = GPUExecutor.ToFloat(state.Reg(stateRegIndex + 2));
                var varA = GPUExecutor.ToFloat(state.Reg(stateRegIndex + 3));

                item.SubItems.Add(varR.ToString());
                item.SubItems.Add(varG.ToString());
                item.SubItems.Add(varB.ToString());
                item.SubItems.Add(varA.ToString());

                if (((varR >= 0.0f) && (varR <= 1.0f)) && ((varG >= 0.0f) && (varG <= 1.0f)) && ((varB >= 0.0f) && (varB <= 1.0f)) && ((varA >= 0.0f) && (varA <= 1.0f)))
                {
                    string txt = String.Format("0x{0:X2}{1:X2}{2:X2}{3:X2}", (int)(varR * 255.0f), (int)(varG * 255.0f), (int)(varB * 255.0f), (int)(varA * 255.0f));
                    item.SubItems.Add(txt);

                    var colorItem = item.SubItems.Add(" ");
                    colorItem.BackColor          = Color.FromArgb((int)(varR * 255.0f), (int)(varG * 255.0f), (int)(varB * 255.0f));
                    item.UseItemStyleForSubItems = false;
                }
                else
                {
                    item.SubItems.Add("-");
                    item.SubItems.Add("-");
                }

                view.Items.Add(item);
            }

            view.EndUpdate();
            view.Refresh();
        }
        public GPUStateCaptureViewport(GPUStateCapture captureFrom)
        {
            var regSurfaceInfo         = captureFrom.Reg(GPURegisterName.RB_SURFACE_INFO);
            var regPaClVteCntl         = captureFrom.Reg(GPURegisterName.PA_CL_VTE_CNTL);
            var regPaSuScModeCntl      = captureFrom.Reg(GPURegisterName.PA_SU_SC_MODE_CNTL);
            var regPaScWindowOffset    = captureFrom.Reg(GPURegisterName.PA_SC_WINDOW_OFFSET);
            var regPaScWindowScissorTL = captureFrom.Reg(GPURegisterName.PA_SC_WINDOW_SCISSOR_TL);
            var regPaScWindowScissorBR = captureFrom.Reg(GPURegisterName.PA_SC_WINDOW_SCISSOR_BR);
            var regPaClVportXoffset    = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_XOFFSET);
            var regPaClVportYoffset    = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_YOFFSET);
            var regPaClVportZoffset    = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_ZOFFSET);
            var regPaClVportXscale     = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_XSCALE);
            var regPaClVportYscale     = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_YSCALE);
            var regPaClVportZscale     = captureFrom.Reg(GPURegisterName.PA_CL_VPORT_ZSCALE);

            {
                ViewportXYDivided   = (0 != ((regPaClVteCntl >> 8) & 1));
                ViewportZDivided    = 0 != ((regPaClVteCntl >> 9) & 1);
                ViewportWNotDivided = 0 != ((regPaClVteCntl >> 10) & 1);

                NormalizedCoordinates = (0 != (regPaClVteCntl & 1));
            }

            {
                WindowOffsetX = 0;
                WindowOffsetY = 0;
                if (0 != ((regPaSuScModeCntl >> 16) & 1))
                {
                    // extract 15-bit signes values
                    UInt16 ofsX = (UInt16)(regPaScWindowOffset & 0x7FFF);
                    UInt16 ofsY = (UInt16)((regPaScWindowOffset >> 16) & 0x7FFF);

                    if (0 != (ofsX & 0x4000))
                    {
                        ofsX |= 0x8000;
                    }
                    if (0 != (ofsY & 0x4000))
                    {
                        ofsY |= 0x8000;
                    }

                    WindowOffsetX = (Int16)ofsX;
                    WindowOffsetY = (Int16)ofsY;
                }
            }

            {
                ScissorX1 = (int)(regPaScWindowScissorTL & 0x7FFF);
                ScissorY1 = (int)((regPaScWindowScissorTL >> 16) & 0x7FFF);
                ScissorX2 = (int)(regPaScWindowScissorBR & 0x7FFF);
                ScissorY2 = (int)((regPaScWindowScissorBR >> 16) & 0x7FFF);
            }

            {
                XScaleEnabled  = (regPaClVteCntl & (1 << 0)) != 0;
                XOffsetEnabled = (regPaClVteCntl & (1 << 1)) != 0;
                YScaleEnabled  = (regPaClVteCntl & (1 << 2)) != 0;
                YOffsetEnabled = (regPaClVteCntl & (1 << 3)) != 0;
                ZScaleEnabled  = (regPaClVteCntl & (1 << 4)) != 0;
                ZOffsetEnabled = (regPaClVteCntl & (1 << 5)) != 0;

                XScale  = XScaleEnabled ? ToFloat(regPaClVportXscale) : 0.0f;
                YScale  = YScaleEnabled ? ToFloat(regPaClVportYscale) : 0.0f;
                ZScale  = ZScaleEnabled ? ToFloat(regPaClVportZscale) : 0.0f;
                XOffset = XOffsetEnabled ? ToFloat(regPaClVportXoffset) : 0.0f;
                YOffset = YOffsetEnabled ? ToFloat(regPaClVportYoffset) : 0.0f;
                ZOffset = ZOffsetEnabled ? ToFloat(regPaClVportZoffset) : 0.0f;
            }
        }
        public GPUStateRenderTargets(GPUStateCapture state)
        {
            var regModeControl    = state.Reg(GPURegisterName.RB_MODECONTROL);
            var regSurfaceInfo    = state.Reg(GPURegisterName.RB_SURFACE_INFO);
            var regColor0Info     = state.Reg(GPURegisterName.RB_COLOR_INFO);
            var regColor1Info     = state.Reg(GPURegisterName.RB_COLOR1_INFO);
            var regColor2Info     = state.Reg(GPURegisterName.RB_COLOR2_INFO);
            var regColor3Info     = state.Reg(GPURegisterName.RB_COLOR3_INFO);
            var regColorMask      = state.Reg(GPURegisterName.RB_COLOR_MASK);
            var regDepthInfo      = state.Reg(GPURegisterName.RB_DEPTH_INFO);
            var regDepthControl   = state.Reg(GPURegisterName.RB_DEPTHCONTROL);
            var regStencilRefMask = state.Reg(GPURegisterName.RB_STENCILREFMASK);

            // read standard stuff
            MSAA         = (GPUMsaaSamples)((regSurfaceInfo >> 16) & 3);
            SurfacePitch = regSurfaceInfo & 0x3FFF;

            // reset color/depth state
            Color = new ColorState[4];
            Depth = new DepthState();

            // read surface settings
            var enableMode = (GPUModeControl)(regModeControl & 0x7);

            if (enableMode == GPUModeControl.ColorDepth)
            {
                UInt32[] regColor = { regColor0Info, regColor1Info, regColor2Info, regColor3Info };

                for (int rtIndex = 0; rtIndex < 4; ++rtIndex)
                {
                    var rtInfo = regColor[rtIndex];

                    // get color mask for this specific render target
                    var writeMask = (regColorMask >> (rtIndex * 4)) & 0xF;
                    if (writeMask != 0)
                    {
                        ColorState colorInfo = new ColorState();
                        colorInfo.WriteRed   = (writeMask & 1) != 0;
                        colorInfo.WriteGreen = (writeMask & 2) != 0;
                        colorInfo.WriteBlue  = (writeMask & 4) != 0;
                        colorInfo.WriteAlpha = (writeMask & 8) != 0;
                        colorInfo.Enabled    = true;
                        colorInfo.EdramBase  = (rtInfo & 0xFFF); // tile address
                        colorInfo.Format     = (GPUColorRenderTargetFormat)((rtInfo >> 16) & 0xF);
                        Color[rtIndex]       = colorInfo;
                    }
                }
            }

            // depth
            {
                var usesDepth        = (0 != (regDepthControl & 0x00000002)) || (0 != (regDepthControl & 0x00000004));
                var stencilWriteMask = (regStencilRefMask & 0x00FF0000) >> 16;
                var usesStencil      = (0 != (regDepthControl & 0x00000001)) || (stencilWriteMask != 0);

                if (usesDepth || usesStencil)
                {
                    DepthState depthState = new DepthState();
                    depthState.Enabled   = true;
                    depthState.EdramBase = (regDepthInfo & 0xFFF);
                    depthState.Format    = (GPUDepthRenderTargetFormat)((regDepthInfo >> 16) & 1);
                    Depth = depthState;
                }
            }
        }