gem5  v20.1.0.0
pixelpump.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 2017 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "dev/pixelpump.hh"
39 
41  640, 480,
42  48, 96, 16,
43  33, 2, 10);
44 
45 
46 DisplayTimings::DisplayTimings(unsigned _width, unsigned _height,
47  unsigned hbp, unsigned h_sync, unsigned hfp,
48  unsigned vbp, unsigned v_sync, unsigned vfp)
49  : width(_width), height(_height),
50  hBackPorch(hbp), hFrontPorch(hfp), hSync(h_sync),
51  vBackPorch(vbp), vFrontPorch(vfp), vSync(v_sync)
52 {
53 }
54 
55 void
57 {
60 
64 
68 }
69 
70 void
72 {
75 
79 
83 }
84 
85 
87  unsigned pixel_chunk)
88  : EventManager(em), Clocked(pxl_clk), Serializable(),
89  pixelChunk(pixel_chunk),
90  pixelEvents(),
91  evVSyncBegin("evVSyncBegin", this, &BasePixelPump::onVSyncBegin),
92  evVSyncEnd("evVSyncEnd", this, &BasePixelPump::onVSyncEnd),
93  evHSyncBegin("evHSyncBegin", this, &BasePixelPump::onHSyncBegin),
94  evHSyncEnd("evHSyncEnd", this, &BasePixelPump::onHSyncEnd),
95  evBeginLine("evBeginLine", this, &BasePixelPump::beginLine),
96  evRenderPixels("evRenderPixels", this, &BasePixelPump::renderPixels),
97  _timings(DisplayTimings::vga),
98  line(0), _posX(0), _underrun(false)
99 {
100 }
101 
103 {
104 }
105 
106 void
108 {
112 
114  SERIALIZE_OBJ(fb);
115 
116  for (PixelEvent *event : pixelEvents)
117  event->serializeSection(cp, event->name());
118 }
119 
120 void
122 {
126 
129 
130  // We don't need to reschedule the event here since the event was
131  // suspended by PixelEvent::drain() and will be rescheduled by
132  // PixelEvent::drainResume().
133  for (PixelEvent *event : pixelEvents)
134  event->unserializeSection(cp, event->name());
135 }
136 
137 void
139 {
140  panic_if(active(), "Trying to update timings in active PixelPump\n");
141 
142  _timings = timings;
143 
144  // Resize the frame buffer if needed
145  if (_timings.width != fb.width() || _timings.height != fb.height())
147 
148  // Set the current line past the last line in the frame. This
149  // triggers the new frame logic in beginLine().
151 }
152 
153 void
155 {
157 }
158 
159 
160 void
162 {
163  if (evVSyncEnd.scheduled())
165 
166  if (evHSyncBegin.scheduled())
168 
169  if (evHSyncEnd.scheduled())
171 
172  if (evBeginLine.scheduled())
174 
177 }
178 
179 void
181 {
182  _posX = 0;
183  line++;
184  if (line >= _timings.linesPerFrame()) {
185  _underrun = false;
186  line = 0;
187  }
188 
189  if (line == _timings.lineVSyncStart()) {
190  onVSyncBegin();
191  } else if (line == _timings.lineVBackPorchStart()) {
192  onVSyncEnd();
193  }
194 
195  const Cycles h_sync_begin(0);
196  schedule(evHSyncBegin, clockEdge(h_sync_begin));
197 
198  const Cycles h_sync_end(h_sync_begin + _timings.hSync);
199  schedule(evHSyncEnd, clockEdge(h_sync_end));
200 
201  // Visible area
202  if (line >= _timings.lineFirstVisible() &&
204 
205  const Cycles h_first_visible(h_sync_end + _timings.hBackPorch);
206  schedule(evRenderPixels, clockEdge(h_first_visible));
207  }
208 
210 }
211 
212 void
214 {
215  // Try to handle multiple pixels at a time; doing so reduces the
216  // accuracy of the underrun detection but lowers simulation
217  // overhead
218  const unsigned x_end(std::min(_posX + pixelChunk, _timings.width));
219  const unsigned pxl_count(x_end - _posX);
220  const unsigned pos_y(posY());
221 
222  Pixel pixel(0, 0, 0);
223  const Pixel underrun_pixel(0, 0, 0);
224  for (; _posX < x_end && !_underrun; ++_posX) {
225  if (!nextPixel(pixel)) {
226  warn("Input buffer underrun in BasePixelPump (%u, %u)\n",
227  _posX, pos_y);
228  _underrun = true;
229  onUnderrun(_posX, pos_y);
230  pixel = underrun_pixel;
231  }
232  fb.pixel(_posX, pos_y) = pixel;
233  }
234 
235  // Fill remaining pixels with a dummy pixel value if we ran out of
236  // data
237  for (; _posX < x_end; ++_posX)
238  fb.pixel(_posX, pos_y) = underrun_pixel;
239 
240  // Schedule a new event to handle the next block of pixels
241  if (_posX < _timings.width) {
242  schedule(evRenderPixels, clockEdge(Cycles(pxl_count)));
243  } else {
244  if (pos_y == _timings.height - 1)
245  onFrameDone();
246  }
247 }
248 
249 void
251 {
252  _underrun = false;
253  line = 0;
254 
255  // Signal vsync end and render the frame
257  onVSyncEnd();
258 
259  // We only care about the visible screen area when rendering the
260  // frame
261  for (line = _timings.lineFirstVisible();
263  ++line) {
264 
265  _posX = 0;
266 
267  onHSyncBegin();
268  onHSyncEnd();
269 
270  renderLine();
271  }
272 
274  onFrameDone();
275 
276  // Signal vsync until the next frame begins
278  onVSyncBegin();
279 }
280 
281 void
283 {
284  const unsigned pos_y(posY());
285 
286  Pixel pixel(0, 0, 0);
287  for (_posX = 0; _posX < _timings.width; ++_posX) {
288  if (!nextPixel(pixel)) {
289  panic("Unexpected underrun in BasePixelPump (%u, %u)\n",
290  _posX, pos_y);
291  }
292  fb.pixel(_posX, pos_y) = pixel;
293  }
294 }
295 
296 
298  const char *name, BasePixelPump *_parent, CallbackType _func)
299  : Event(), Drainable(),
300  _name(name), parent(*_parent), func(_func),
301  suspended(false),
302  relativeTick(0)
303 {
304  parent.pixelEvents.push_back(this);
305 }
306 
309 {
310  if (scheduled())
311  suspend();
312  return DrainState::Drained;
313 }
314 
315 void
317 {
318  if (suspended)
319  resume();
320 }
321 
322 void
324 {
325  assert(!scheduled());
327  SERIALIZE_SCALAR(suspended);
328  SERIALIZE_SCALAR(relativeTick);
329 }
330 
331 void
333 {
335  UNSERIALIZE_SCALAR(suspended);
336  UNSERIALIZE_SCALAR(relativeTick);
337  assert(!scheduled());
338 }
339 
340 void
342 {
343  assert(scheduled());
344  assert(!suspended);
345 
346  suspended = true;
347  relativeTick = when() - curTick();
348  parent.deschedule(this);
349 }
350 
351 void
353 {
354  assert(!scheduled());
355  assert(suspended);
356  parent.schedule(this, relativeTick + curTick());
357  suspended = false;
358  relativeTick = 0;
359 }
DisplayTimings::cyclesPerLine
Cycles cyclesPerLine() const
How many pixel clocks are required for one line?
Definition: pixelpump.hh:68
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:460
UNSERIALIZE_OBJ
#define UNSERIALIZE_OBJ(obj)
Definition: serialize.hh:889
DisplayTimings::lineVSyncStart
unsigned lineVSyncStart() const
Calculate the first line of the vsync signal.
Definition: pixelpump.hh:78
Event::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: eventq.cc:247
warn
#define warn(...)
Definition: logging.hh:239
BasePixelPump::BasePixelPump
BasePixelPump(EventManager &em, ClockDomain &pxl_clk, unsigned pixel_chunk)
Definition: pixelpump.cc:86
DisplayTimings::linesPerFrame
unsigned linesPerFrame() const
Calculate the total number of lines in a frame.
Definition: pixelpump.hh:98
Clocked
Helper class for objects that need to be clocked.
Definition: clocked_object.hh:59
BasePixelPump::_timings
DisplayTimings _timings
Definition: pixelpump.hh:306
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
DisplayTimings::vga
static const DisplayTimings vga
Definition: pixelpump.hh:121
BasePixelPump::active
bool active() const
Is the pixel pump active and refreshing the display?
Definition: pixelpump.hh:173
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
FrameBuffer::resize
void resize(unsigned width, unsigned height)
Resize the frame buffer.
Definition: framebuffer.cc:80
ArmISA::width
Bitfield< 4 > width
Definition: miscregs_types.hh:68
DisplayTimings::vBackPorch
unsigned vBackPorch
Vertical back porch in lines.
Definition: pixelpump.hh:115
BasePixelPump::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pixelpump.cc:121
DisplayTimings::lineVBackPorchStart
unsigned lineVBackPorchStart() const
Calculate the first line of the vertical back porch.
Definition: pixelpump.hh:83
BasePixelPump::onHSyncBegin
virtual void onHSyncBegin()
Start of the HSync region.
Definition: pixelpump.hh:219
BasePixelPump::PixelEvent::drainResume
void drainResume() override
Resume execution after a successful drain.
Definition: pixelpump.cc:316
EventManager::deschedule
void deschedule(Event &event)
Definition: eventq.hh:1014
pixelpump.hh
FrameBuffer::pixel
const Pixel & pixel(unsigned x, unsigned y) const
Get a pixel from an (x, y) coordinate.
Definition: framebuffer.hh:157
DisplayTimings::vFrontPorch
unsigned vFrontPorch
Vertical front porch in lines.
Definition: pixelpump.hh:117
BasePixelPump::evRenderPixels
PixelEvent evRenderPixels
Definition: pixelpump.hh:304
ClockDomain
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Definition: clock_domain.hh:68
BasePixelPump::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pixelpump.cc:107
BasePixelPump::pixelEvents
std::vector< PixelEvent * > pixelEvents
Convenience vector when doing operations on all events.
Definition: pixelpump.hh:297
BasePixelPump::evHSyncBegin
PixelEvent evHSyncBegin
Definition: pixelpump.hh:301
DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
BasePixelPump
Timing generator for a pixel-based display.
Definition: pixelpump.hh:144
BasePixelPump::posY
unsigned posY() const
Current pixel position within the visible area.
Definition: pixelpump.hh:188
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
BasePixelPump::beginLine
void beginLine()
Definition: pixelpump.cc:180
BasePixelPump::start
void start()
Starting pushing pixels in timing mode.
Definition: pixelpump.cc:154
BasePixelPump::onFrameDone
virtual void onFrameDone()
Finished displaying the visible region of a frame.
Definition: pixelpump.hh:242
cp
Definition: cprintf.cc:40
DisplayTimings::lineFrontPorchStart
unsigned lineFrontPorchStart() const
Calculate the first line of the back porch.
Definition: pixelpump.hh:93
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
BasePixelPump::PixelEvent
Callback helper class with suspend support.
Definition: pixelpump.hh:258
DisplayTimings::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pixelpump.cc:56
Drainable
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:230
Event
Definition: eventq.hh:246
DisplayTimings::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pixelpump.cc:71
SERIALIZE_OBJ
#define SERIALIZE_OBJ(obj)
Definition: serialize.hh:882
BasePixelPump::PixelEvent::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: pixelpump.cc:308
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
DisplayTimings::hBackPorch
unsigned hBackPorch
Horizontal back porch in pixels.
Definition: pixelpump.hh:108
BasePixelPump::~BasePixelPump
virtual ~BasePixelPump()
Definition: pixelpump.cc:102
BasePixelPump::fb
FrameBuffer fb
Output frame buffer.
Definition: pixelpump.hh:193
Clocked::clockEdge
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Definition: clocked_object.hh:174
BasePixelPump::nextPixel
virtual bool nextPixel(Pixel &p)=0
Get the next pixel from the scan line buffer.
X86ISA::em
Bitfield< 2 > em
Definition: misc.hh:602
DisplayTimings::width
unsigned width
Display width in pixels.
Definition: pixelpump.hh:103
BasePixelPump::onHSyncEnd
virtual void onHSyncEnd()
Start of the first pixel after the HSync region.
Definition: pixelpump.hh:227
BasePixelPump::PixelEvent::resume
void resume()
Definition: pixelpump.cc:352
BasePixelPump::timings
const DisplayTimings & timings() const
Get a constant reference of the current display timings.
Definition: pixelpump.hh:170
Pixel
Internal gem5 representation of a Pixel.
Definition: pixel.hh:54
BasePixelPump::PixelEvent::suspend
void suspend()
Definition: pixelpump.cc:341
BasePixelPump::updateTimings
void updateTimings(const DisplayTimings &timings)
Update frame size using display timing.
Definition: pixelpump.cc:138
name
const std::string & name()
Definition: trace.cc:50
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
BasePixelPump::line
unsigned line
Current line (including back porch, front porch, and vsync) within a frame.
Definition: pixelpump.hh:312
DisplayTimings::height
unsigned height
Display height in pixels.
Definition: pixelpump.hh:105
BasePixelPump::onUnderrun
virtual void onUnderrun(unsigned x, unsigned y)
Buffer underrun occurred on a frame.
Definition: pixelpump.hh:239
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
BasePixelPump::PixelEvent::parent
BasePixelPump & parent
Definition: pixelpump.hh:283
DisplayTimings::lineFirstVisible
unsigned lineFirstVisible() const
Calculate the first line of the visible region.
Definition: pixelpump.hh:88
BasePixelPump::renderPixels
void renderPixels()
Definition: pixelpump.cc:213
BasePixelPump::evVSyncEnd
PixelEvent evVSyncEnd
Definition: pixelpump.hh:300
BasePixelPump::evHSyncEnd
PixelEvent evHSyncEnd
Definition: pixelpump.hh:302
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
DisplayTimings::hFrontPorch
unsigned hFrontPorch
Horizontal front porch in pixels.
Definition: pixelpump.hh:110
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
BasePixelPump::PixelEvent::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pixelpump.cc:323
EventManager
Definition: eventq.hh:973
DisplayTimings
Definition: pixelpump.hh:46
BasePixelPump::PixelEvent::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pixelpump.cc:332
FrameBuffer::width
unsigned width() const
Frame buffer width in pixels.
Definition: framebuffer.hh:96
FrameBuffer::height
unsigned height() const
Frame buffer height in pixels.
Definition: framebuffer.hh:98
DisplayTimings::vSync
unsigned vSync
Vertical sync signal in lines.
Definition: pixelpump.hh:119
BasePixelPump::_posX
unsigned _posX
X-coordinate within the visible region of a frame.
Definition: pixelpump.hh:314
BasePixelPump::PixelEvent::PixelEvent
PixelEvent(const char *name, BasePixelPump *parent, CallbackType func)
Definition: pixelpump.cc:297
BasePixelPump::onVSyncBegin
virtual void onVSyncBegin()
First pixel clock of the first VSync line.
Definition: pixelpump.hh:205
CheckpointIn
Definition: serialize.hh:67
BasePixelPump::stop
void stop()
Immediately stop pushing pixels.
Definition: pixelpump.cc:161
DisplayTimings::DisplayTimings
DisplayTimings(unsigned width, unsigned height, unsigned hbp, unsigned h_sync, unsigned hfp, unsigned vbp, unsigned v_sync, unsigned vfp)
Create a display timing configuration struct.
Definition: pixelpump.cc:46
BasePixelPump::renderLine
void renderLine()
Fast and event-free line rendering function.
Definition: pixelpump.cc:282
BasePixelPump::onVSyncEnd
virtual void onVSyncEnd()
Callback on the first pixel of the line after the end VSync region (typically the first pixel of the ...
Definition: pixelpump.hh:211
BasePixelPump::renderFrame
void renderFrame()
Render an entire frame in KVM execution mode.
Definition: pixelpump.cc:250
BasePixelPump::pixelChunk
const unsigned pixelChunk
Maximum number of pixels to handle per render callback.
Definition: pixelpump.hh:242
BasePixelPump::_underrun
bool _underrun
Did a buffer underrun occur within this refresh interval?
Definition: pixelpump.hh:317
BasePixelPump::evBeginLine
PixelEvent evBeginLine
Definition: pixelpump.hh:303
Event::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: eventq.cc:238
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
DisplayTimings::hSync
unsigned hSync
Horizontal sync signal length in pixels.
Definition: pixelpump.hh:112
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17