-
Notifications
You must be signed in to change notification settings - Fork 15
/
replayer_driver_parallel.cpp
218 lines (188 loc) · 6.38 KB
/
replayer_driver_parallel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* Copyright (c) 2020 Themaister
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "replayer_driver.hpp"
#include "device.hpp"
#include "rdp_device.hpp"
#include "aligned_alloc.hpp"
namespace RDP
{
class ParallelReplayer : public ReplayerDriver
{
public:
ParallelReplayer(Vulkan::Device &device, CommandInterface &player_,
ReplayerEventInterface &iface_, bool benchmarking, bool upscale)
: player(player_)
, iface(iface_)
, host_memory(Util::memalign_calloc(64 * 1024, player.get_rdram_size()))
, gpu(device, host_memory.get(), 0, player.get_rdram_size(), player.get_hidden_rdram_size(),
(benchmarking ? 0 : (COMMAND_PROCESSOR_FLAG_HOST_VISIBLE_HIDDEN_RDRAM_BIT | COMMAND_PROCESSOR_FLAG_HOST_VISIBLE_TMEM_BIT)) |
(upscale ? COMMAND_PROCESSOR_FLAG_UPSCALING_2X_BIT : 0))
{
if (!gpu.device_is_supported())
throw std::runtime_error("GPU is not supported.");
gpu.set_validation_interface(&validation_iface);
}
private:
CommandInterface &player;
ReplayerEventInterface &iface;
struct ValidationErrorAborter : ValidationInterface
{
void report_rdp_crash(ValidationError, const char *msg) override
{
LOGE("RDP crash: %s\n", msg);
abort();
}
} validation_iface;
struct AlignedDeleter
{
void operator()(void *ptr)
{
Util::memalign_free(ptr);
}
};
std::unique_ptr<void, AlignedDeleter> host_memory;
CommandProcessor gpu;
void eof() override;
void signal_complete() override;
void update_rdram(const void *data, size_t size, size_t offset) override;
void update_hidden_rdram(const void *data, size_t size, size_t offset) override;
void command(Op command_id, uint32_t word_count, const uint32_t *words) override;
void end_frame() override;
void set_vi_register(VIRegister index, uint32_t value) override;
uint8_t *get_rdram() override;
size_t get_rdram_size() override;
uint8_t *get_hidden_rdram() override;
size_t get_hidden_rdram_size() override;
uint8_t *get_tmem() override;
void idle() override;
void invalidate_caches() override;
void flush_caches() override;
void begin_vi_register_per_scanline() override;
void set_vi_register_for_scanline(unsigned vi_line, uint32_t h_start, uint32_t x_scale) override;
void end_vi_register_per_scanline() override;
void set_crop_rect(unsigned left, unsigned right, unsigned top, unsigned bottom) override;
ScanoutOptions::CropRect crop_rect;
};
void ParallelReplayer::begin_vi_register_per_scanline()
{
gpu.begin_vi_register_per_scanline(VideoInterface::PER_SCANLINE_HSTART_BIT |
VideoInterface::PER_SCANLINE_XSCALE_BIT);
}
void ParallelReplayer::set_vi_register_for_scanline(unsigned vi_line, uint32_t h_start, uint32_t x_scale)
{
gpu.set_vi_register_for_scanline(VideoInterface::PER_SCANLINE_HSTART_BIT, h_start);
gpu.set_vi_register_for_scanline(VideoInterface::PER_SCANLINE_XSCALE_BIT, x_scale);
gpu.latch_vi_register_for_scanline(vi_line);
}
void ParallelReplayer::end_vi_register_per_scanline()
{
gpu.end_vi_register_per_scanline();
}
void ParallelReplayer::set_crop_rect(unsigned left, unsigned right, unsigned top, unsigned bottom)
{
crop_rect = { left, right, top, bottom, true };
}
void ParallelReplayer::eof()
{
iface.eof();
}
void ParallelReplayer::signal_complete()
{
gpu.flush();
iface.signal_complete();
}
void ParallelReplayer::update_rdram(const void *data, size_t size, size_t offset)
{
gpu.idle();
memcpy(static_cast<uint8_t *>(host_memory.get()) + offset, data, size);
gpu.end_write_rdram();
}
void ParallelReplayer::flush_caches()
{
gpu.end_write_rdram();
gpu.end_write_hidden_rdram();
}
void ParallelReplayer::invalidate_caches()
{
gpu.begin_read_rdram();
gpu.begin_read_hidden_rdram();
}
void ParallelReplayer::update_hidden_rdram(const void *data, size_t size, size_t offset)
{
gpu.idle();
memcpy(static_cast<uint8_t *>(gpu.begin_read_hidden_rdram()) + offset, data, size);
gpu.end_write_hidden_rdram();
}
void ParallelReplayer::command(Op command_id, uint32_t num_words, const uint32_t *words)
{
gpu.enqueue_command(num_words, words);
iface.notify_command(command_id, num_words, words);
}
uint8_t *ParallelReplayer::get_rdram()
{
gpu.idle();
return static_cast<uint8_t *>(host_memory.get());
}
size_t ParallelReplayer::get_rdram_size()
{
return gpu.get_rdram_size();
}
uint8_t *ParallelReplayer::get_hidden_rdram()
{
gpu.idle();
return static_cast<uint8_t *>(gpu.begin_read_hidden_rdram());
}
size_t ParallelReplayer::get_hidden_rdram_size()
{
return gpu.get_hidden_rdram_size();
}
uint8_t *ParallelReplayer::get_tmem()
{
gpu.idle();
return static_cast<uint8_t *>(gpu.get_tmem());
}
void ParallelReplayer::idle()
{
gpu.idle();
}
void ParallelReplayer::end_frame()
{
std::vector<RGBA> colors;
unsigned width, height;
ScanoutOptions opts = {};
opts.blend_previous_frame = true;
opts.upscale_deinterlacing = false;
opts.crop_rect = crop_rect;
gpu.scanout_sync(colors, width, height, opts);
iface.update_screen(colors.data(), width, height, width);
crop_rect.enable = false;
}
void ParallelReplayer::set_vi_register(VIRegister index, uint32_t value)
{
gpu.set_vi_register(index, value);
}
std::unique_ptr<ReplayerDriver> create_replayer_driver_parallel(Vulkan::Device &device, CommandInterface &player, ReplayerEventInterface &iface,
bool benchmarking, bool upscale)
{
return std::make_unique<ParallelReplayer>(device, player, iface, benchmarking, upscale);
}
}