CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Common/GPUDebugInterface.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>20#include <string>2122#include "Common/Math/expression_parser.h"23#include "Core/MemMap.h"24#include "GPU/GPU.h"25#include "GPU/GPUInterface.h"2627struct GPUDebugOp {28u32 pc;29u8 cmd;30u32 op;31std::string desc;32};3334enum GPUDebugBufferFormat {35// These match GEBufferFormat.36GPU_DBG_FORMAT_565 = 0,37GPU_DBG_FORMAT_5551 = 1,38GPU_DBG_FORMAT_4444 = 2,39GPU_DBG_FORMAT_8888 = 3,40GPU_DBG_FORMAT_INVALID = 0xFF,4142// These are reversed versions.43GPU_DBG_FORMAT_REVERSE_FLAG = 4,44GPU_DBG_FORMAT_565_REV = 4,45GPU_DBG_FORMAT_5551_REV = 5,46GPU_DBG_FORMAT_4444_REV = 6,4748// 565 is just reversed, the others have B and R swapped.49GPU_DBG_FORMAT_565_BGRA = 0x04,50GPU_DBG_FORMAT_BRSWAP_FLAG = 0x08,51GPU_DBG_FORMAT_5551_BGRA = 0x09,52GPU_DBG_FORMAT_4444_BGRA = 0x0A,53GPU_DBG_FORMAT_8888_BGRA = 0x0B,5455// These don't, they're for depth/stencil buffers.56GPU_DBG_FORMAT_FLOAT = 0x10,57GPU_DBG_FORMAT_16BIT = 0x11,58GPU_DBG_FORMAT_8BIT = 0x12,59GPU_DBG_FORMAT_24BIT_8X = 0x13,60GPU_DBG_FORMAT_24X_8BIT = 0x14,6162GPU_DBG_FORMAT_FLOAT_DIV_256 = 0x18,63GPU_DBG_FORMAT_24BIT_8X_DIV_256 = 0x1B,6465// This is used for screenshots, mainly.66GPU_DBG_FORMAT_888_RGB = 0x20,67};6869enum GPUDebugFramebufferType {70// The current render target.71GPU_DBG_FRAMEBUF_RENDER,72// The current display target (not the displayed screen, though.)73GPU_DBG_FRAMEBUF_DISPLAY,74};7576inline GPUDebugBufferFormat &operator |=(GPUDebugBufferFormat &lhs, const GPUDebugBufferFormat &rhs) {77lhs = GPUDebugBufferFormat((int)lhs | (int)rhs);78return lhs;79}8081struct GPUDebugBuffer {82GPUDebugBuffer() {83}8485GPUDebugBuffer(void *data, u32 stride, u32 height, GEBufferFormat fmt, bool reversed = false)86: alloc_(false), data_((u8 *)data), stride_(stride), height_(height), fmt_(GPUDebugBufferFormat(fmt)), flipped_(false) {87if (reversed && fmt_ < GPU_DBG_FORMAT_8888) {88fmt_ |= GPU_DBG_FORMAT_REVERSE_FLAG;89}90}9192GPUDebugBuffer(void *data, u32 stride, u32 height, GETextureFormat fmt, bool reversed = false)93: alloc_(false), data_((u8 *)data), stride_(stride), height_(height), fmt_(GPUDebugBufferFormat(fmt)), flipped_(false) {94if (reversed && fmt_ < GPU_DBG_FORMAT_8888) {95fmt_ |= GPU_DBG_FORMAT_REVERSE_FLAG;96}97}9899GPUDebugBuffer(void *data, u32 stride, u32 height, GPUDebugBufferFormat fmt)100: alloc_(false), data_((u8 *)data), stride_(stride), height_(height), fmt_(fmt), flipped_(false) {101}102103GPUDebugBuffer(GPUDebugBuffer &&other) noexcept {104alloc_ = other.alloc_;105data_ = other.data_;106height_ = other.height_;107stride_ = other.stride_;108flipped_ = other.flipped_;109fmt_ = other.fmt_;110other.alloc_ = false;111other.data_ = nullptr;112}113114~GPUDebugBuffer() {115Free();116}117118GPUDebugBuffer &operator = (GPUDebugBuffer &&other) noexcept {119if (this != &other) {120Free();121alloc_ = other.alloc_;122data_ = other.data_;123height_ = other.height_;124stride_ = other.stride_;125flipped_ = other.flipped_;126fmt_ = other.fmt_;127other.alloc_ = false;128other.data_ = nullptr;129}130131return *this;132}133134void Allocate(u32 stride, u32 height, GEBufferFormat fmt, bool flipped = false, bool reversed = false);135void Allocate(u32 stride, u32 height, GPUDebugBufferFormat fmt, bool flipped = false);136void Free();137138void ZeroBytes();139140u8 *GetData() {141return data_;142}143144u32 GetRawPixel(int x, int y) const;145void SetRawPixel(int x, int y, u32 c);146147const u8 *GetData() const {148return data_;149}150151u32 GetHeight() const {152return height_;153}154155u32 GetStride() const {156return stride_;157}158159bool GetFlipped() const {160return flipped_;161}162163GPUDebugBufferFormat GetFormat() const {164return fmt_;165}166167u32 PixelSize() const;168169private:170bool alloc_ = false;171u8 *data_ = nullptr;172u32 stride_ = 0;173u32 height_ = 0;174GPUDebugBufferFormat fmt_ = GPU_DBG_FORMAT_INVALID;175bool flipped_ = false;176};177178struct GPUDebugVertex {179float u;180float v;181float x;182float y;183float z;184u8 c[4];185float nx;186float ny;187float nz;188};189190class GPUDebugInterface {191public:192virtual ~GPUDebugInterface() {}193virtual bool GetCurrentDisplayList(DisplayList &list) = 0;194virtual std::vector<DisplayList> ActiveDisplayLists() = 0;195virtual void ResetListPC(int listID, u32 pc) = 0;196virtual void ResetListStall(int listID, u32 stall) = 0;197virtual void ResetListState(int listID, DisplayListState state) = 0;198199GPUDebugOp DissassembleOp(u32 pc) {200return DissassembleOp(pc, Memory::Read_U32(pc));201}202virtual GPUDebugOp DissassembleOp(u32 pc, u32 op) = 0;203virtual std::vector<GPUDebugOp> DissassembleOpRange(u32 startpc, u32 endpc) = 0;204205// Enter/exit stepping mode. Mainly for better debug stats on time taken.206virtual void NotifySteppingEnter() = 0;207virtual void NotifySteppingExit() = 0;208209virtual u32 GetRelativeAddress(u32 data) = 0;210virtual u32 GetVertexAddress() = 0;211virtual u32 GetIndexAddress() = 0;212virtual GPUgstate GetGState() = 0;213// Needs to be called from the GPU thread.214// Calling from a separate thread (e.g. UI) may fail.215virtual void SetCmdValue(u32 op) = 0;216virtual void DispatchFlush() = 0;217218virtual uint32_t SetAddrTranslation(uint32_t value) = 0;219virtual uint32_t GetAddrTranslation() = 0;220221virtual bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {222return false;223}224225// Needs to be called from the GPU thread, so on the same thread as a notification is fine.226// Calling from a separate thread (e.g. UI) may fail.227virtual bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes = -1) {228// False means unsupported.229return false;230}231232// Similar to GetCurrentFramebuffer().233virtual bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) {234return false;235}236237// Similar to GetCurrentFramebuffer().238virtual bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) {239return false;240}241242// Similar to GetCurrentFramebuffer(), with texture level specification.243virtual bool GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) {244return false;245}246247virtual bool GetCurrentClut(GPUDebugBuffer &buffer) {248return false;249}250251virtual bool GetOutputFramebuffer(GPUDebugBuffer &buffer) {252return false;253}254};255256bool GPUDebugInitExpression(GPUDebugInterface *g, const char *str, PostfixExpression &exp);257bool GPUDebugExecExpression(GPUDebugInterface *g, PostfixExpression &exp, uint32_t &result);258bool GPUDebugExecExpression(GPUDebugInterface *g, const char *str, uint32_t &result);259260261