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/Software/SoftGpu.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 <cstdint>20#include "GPU/GPUCommon.h"21#include "GPU/Common/GPUDebugInterface.h"22#include "Common/GPU/thin3d.h"2324struct FormatBuffer {25FormatBuffer() { data = nullptr; }26union {27u8 *data;28u16 *as16;29u32 *as32;30};3132inline void Set16(int x, int y, int stride, u16 v) const {33as16[x + y * stride] = v;34}3536inline void Set32(int x, int y, int stride, u32 v) const {37as32[x + y * stride] = v;38}3940inline u16 Get16(int x, int y, int stride) const {41return as16[x + y * stride];42}4344inline u32 Get32(int x, int y, int stride) const {45return as32[x + y * stride];46}4748inline u16 *Get16Ptr(int x, int y, int stride) const {49return &as16[x + y * stride];50}5152inline u32 *Get32Ptr(int x, int y, int stride) const {53return &as32[x + y * stride];54}55};5657enum class SoftDirty : uint64_t {58NONE = 0,5960PIXEL_BASIC = 1ULL << 0,61PIXEL_STENCIL = 1ULL << 1,62PIXEL_ALPHA = 1ULL << 2,63PIXEL_DITHER = 1ULL << 3,64PIXEL_WRITEMASK = 1ULL << 4,65PIXEL_CACHED = 1ULL << 5,66PIXEL_ALL = 0b111111ULL << 0,6768SAMPLER_BASIC = 1ULL << 6,69SAMPLER_TEXLIST = 1ULL << 7,70SAMPLER_CLUT = 1ULL << 8,71SAMPLER_ALL = 0b111ULL << 6,7273RAST_BASIC = 1ULL << 9,74RAST_TEX = 1ULL << 10,75RAST_OFFSET = 1ULL << 11,76RAST_ALL = 0b111ULL << 9,7778LIGHT_BASIC = 1ULL << 12,79LIGHT_MATERIAL = 1ULL << 13,80LIGHT_0 = 1ULL << 14,81LIGHT_1 = 1ULL << 15,82LIGHT_2 = 1ULL << 16,83LIGHT_3 = 1ULL << 17,84LIGHT_ALL = 0b111111ULL << 12,8586TRANSFORM_BASIC = 1ULL << 18,87TRANSFORM_MATRIX = 1ULL << 19,88TRANSFORM_VIEWPORT = 1ULL << 20,89TRANSFORM_FOG = 1ULL << 21,90TRANSFORM_ALL = 0b1111ULL << 18,9192BINNER_RANGE = 1ULL << 22,93BINNER_OVERLAP = 1ULL << 23,94};95static inline SoftDirty operator |(const SoftDirty &lhs, const SoftDirty &rhs) {96return SoftDirty((uint64_t)lhs | (uint64_t)rhs);97}98static inline SoftDirty &operator |=(SoftDirty &lhs, const SoftDirty &rhs) {99lhs = lhs | rhs;100return lhs;101}102static inline bool operator &(const SoftDirty &lhs, const SoftDirty &rhs) {103return ((uint64_t)lhs & (uint64_t)rhs) != 0;104}105static inline SoftDirty &operator &=(SoftDirty &lhs, const SoftDirty &rhs) {106lhs = SoftDirty((uint64_t)lhs & (uint64_t)rhs);107return lhs;108}109static inline SoftDirty operator ~(const SoftDirty &v) {110return SoftDirty(~(uint64_t)v);111}112113class PresentationCommon;114class SoftwareDrawEngine;115116enum class SoftGPUVRAMDirty : uint8_t {117CLEAR = 0,118DIRTY = 1,119REALLY_DIRTY = 2,120};121122ENUM_CLASS_BITOPS(SoftGPUVRAMDirty);123124class SoftGPU : public GPUCommon {125public:126SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw);127~SoftGPU();128129u32 CheckGPUFeatures() const override { return 0; }130bool IsStarted() override;131void ExecuteOp(u32 op, u32 diff) override;132void FinishDeferred() override;133int ListSync(int listid, int mode) override;134u32 DrawSync(int mode) override;135void UpdateCmdInfo() override {}136137void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override;138void CopyDisplayToOutput(bool reallyDirty) override;139void GetStats(char *buffer, size_t bufsize) override;140std::vector<const VirtualFramebuffer *> GetFramebufferList() const override { return std::vector<const VirtualFramebuffer *>(); }141void InvalidateCache(u32 addr, int size, GPUInvalidationType type) override;142void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format) override;143bool PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags = GPUCopyFlag::NONE) override;144bool PerformMemorySet(u32 dest, u8 v, int size) override;145bool PerformReadbackToMemory(u32 dest, int size) override;146bool PerformWriteColorFromMemory(u32 dest, int size) override;147bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags) override;148149void DeviceLost() override;150void DeviceRestore(Draw::DrawContext *draw) override;151152void NotifyRenderResized() override;153void NotifyDisplayResized() override;154155void CheckDisplayResized() override;156void CheckConfigChanged() override;157158void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) override {159primaryInfo = "Software";160fullInfo = "Software";161}162163bool FramebufferDirty() override;164bool FramebufferReallyDirty() override;165166bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes = -1) override;167bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;168bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override;169bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;170bool GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;171bool GetCurrentClut(GPUDebugBuffer &buffer) override;172bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;173174bool DescribeCodePtr(const u8 *ptr, std::string &name) override;175176void Execute_BlockTransferStart(u32 op, u32 diff);177void Execute_Prim(u32 op, u32 diff);178void Execute_Bezier(u32 op, u32 diff);179void Execute_Spline(u32 op, u32 diff);180void Execute_LoadClut(u32 op, u32 diff);181void Execute_FramebufPtr(u32 op, u32 diff);182void Execute_FramebufFormat(u32 op, u32 diff);183void Execute_ZbufPtr(u32 op, u32 diff);184void Execute_VertexType(u32 op, u32 diff);185186// Overridden to change flushing behavior.187void Execute_Call(u32 op, u32 diff);188189// Overridden for a dirty flag change.190void Execute_BoundingBox(u32 op, u32 diff);191192void Execute_WorldMtxNum(u32 op, u32 diff);193void Execute_ViewMtxNum(u32 op, u32 diff);194void Execute_ProjMtxNum(u32 op, u32 diff);195void Execute_TgenMtxNum(u32 op, u32 diff);196void Execute_BoneMtxNum(u32 op, u32 diff);197198void Execute_WorldMtxData(u32 op, u32 diff);199void Execute_ViewMtxData(u32 op, u32 diff);200void Execute_ProjMtxData(u32 op, u32 diff);201void Execute_TgenMtxData(u32 op, u32 diff);202void Execute_BoneMtxData(u32 op, u32 diff);203204bool GetMatrix24(GEMatrixType type, u32_le *result, u32 cmdbits) override;205void ResetMatrices() override;206207void Execute_ImmVertexAlphaPrim(u32 op, u32 diff);208209typedef void (SoftGPU::*CmdFunc)(u32 op, u32 diff);210211protected:212void FastRunLoop(DisplayList &list) override;213void CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight);214void ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, int srcheight, const uint16_t *overrideData = nullptr);215216void BuildReportingInfo() override {}217218private:219void MarkDirty(uint32_t addr, uint32_t stride, uint32_t height, GEBufferFormat fmt, SoftGPUVRAMDirty value);220void MarkDirty(uint32_t addr, uint32_t bytes, SoftGPUVRAMDirty value);221bool ClearDirty(uint32_t addr, uint32_t stride, uint32_t height, GEBufferFormat fmt, SoftGPUVRAMDirty value);222bool ClearDirty(uint32_t addr, uint32_t bytes, SoftGPUVRAMDirty value);223224uint8_t vramDirty_[2048];225uint32_t lastDirtyAddr_ = 0;226uint32_t lastDirtySize_ = 0;227SoftGPUVRAMDirty lastDirtyValue_ = SoftGPUVRAMDirty::CLEAR;228229u32 displayFramebuf_;230u32 displayStride_;231GEBufferFormat displayFormat_;232SoftDirty dirtyFlags_ = SoftDirty(-1);233234PresentationCommon *presentation_ = nullptr;235SoftwareDrawEngine *drawEngine_ = nullptr;236237Draw::Texture *fbTex = nullptr;238std::vector<u32> fbTexBuffer_;239};240241// TODO: These shouldn't be global.242extern uint8_t clut[1024];243extern FormatBuffer fb;244extern FormatBuffer depthbuf;245246// Type for the DarkStalkers stretch replacement.247enum class DSStretch {248Off = 0,249Normal,250Wide,251};252253254