Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Debugger/Record.h
3187 views
1
// Copyright (c) 2017- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <functional>
21
#include <atomic>
22
#include <vector>
23
#include <set>
24
25
#include "Common/CommonTypes.h"
26
#include "GPU/Debugger/RecordFormat.h"
27
28
class Path;
29
30
namespace GPURecord {
31
32
constexpr uint32_t DIRTY_VRAM_SHIFT = 8;
33
constexpr uint32_t DIRTY_VRAM_ROUND = (1 << DIRTY_VRAM_SHIFT) - 1;
34
constexpr uint32_t DIRTY_VRAM_SIZE = (2 * 1024 * 1024) >> DIRTY_VRAM_SHIFT;
35
constexpr uint32_t DIRTY_VRAM_MASK = (2 * 1024 * 1024 - 1) >> DIRTY_VRAM_SHIFT;
36
enum class DirtyVRAMFlag : uint8_t {
37
CLEAN = 0,
38
UNKNOWN = 1,
39
DIRTY = 2,
40
DRAWN = 3,
41
};
42
43
class Recorder {
44
public:
45
bool IsActive() const {
46
return active;
47
}
48
bool IsActivePending() const {
49
return nextFrame || active;
50
}
51
bool RecordNextFrame(const std::function<void(const Path &)> callback);
52
void ClearCallback() {
53
// Not super thread safe..
54
writeCallback = nullptr;
55
}
56
57
void NotifyCommand(u32 pc);
58
void NotifyMemcpy(u32 dest, u32 src, u32 sz);
59
void NotifyMemset(u32 dest, int v, u32 sz);
60
void NotifyUpload(u32 dest, u32 sz);
61
void NotifyDisplay(u32 addr, int stride, int fmt);
62
void NotifyBeginFrame();
63
void NotifyCPU();
64
private:
65
void FlushRegisters();
66
void DirtyAllVRAM(DirtyVRAMFlag flag);
67
void DirtyVRAM(u32 start, u32 sz, DirtyVRAMFlag flag);
68
void DirtyDrawnVRAM();
69
70
bool BeginRecording();
71
Path WriteRecording();
72
73
bool HasDrawCommands() const;
74
void CheckEdramTrans();
75
void FinishRecording();
76
77
Command EmitCommandWithRAM(CommandType t, const void *p, u32 sz, u32 align);
78
79
void UpdateLastVRAM(u32 addr, u32 bytes);
80
void ClearLastVRAM(u32 addr, u8 c, u32 bytes);
81
int CompareLastVRAM(u32 addr, u32 bytes) const;
82
83
u32 GetTargetFlags(u32 addr, u32 sizeInRAM);
84
85
void FlushPrimState(int vcount);
86
void EmitTextureData(int level, u32 texaddr);
87
void EmitTransfer(u32 op);
88
void EmitClut(u32 op);
89
void EmitPrim(u32 op);
90
void EmitBezierSpline(u32 op);
91
92
bool active = false;
93
std::atomic<bool> nextFrame = false;
94
int flipLastAction = -1;
95
int flipFinishAt = -1;
96
uint32_t lastEdramTrans = 0x400;
97
std::function<void(const Path &)> writeCallback;
98
99
std::vector<u8> pushbuf;
100
std::vector<Command> commands;
101
std::vector<u32> lastRegisters;
102
std::vector<u32> lastTextures;
103
std::set<u32> lastRenderTargets;
104
std::vector<u8> lastVRAM;
105
106
DirtyVRAMFlag dirtyVRAM[DIRTY_VRAM_SIZE];
107
};
108
109
} // namespace GPURecord
110
111