0% found this document useful (0 votes)
99 views

Introduction To Software Rendering On Embedded Systems

Software rendering on embedded systems involves drawing graphics through code rather than using a graphics processing unit (GPU). The process begins by drawing individual pixels and using them to draw lines and triangles. Triangles are useful because any 3D model can be represented as a collection of triangles. Drawing and filling triangles allows creating solid shapes. This basic rendering process can be implemented on a microcontroller by using a frame buffer to store pixels and sending that data to drive an LCD screen. Data structures, algorithms, and optimization techniques are important considerations for efficient embedded software.

Uploaded by

Ahmed Hamouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Introduction To Software Rendering On Embedded Systems

Software rendering on embedded systems involves drawing graphics through code rather than using a graphics processing unit (GPU). The process begins by drawing individual pixels and using them to draw lines and triangles. Triangles are useful because any 3D model can be represented as a collection of triangles. Drawing and filling triangles allows creating solid shapes. This basic rendering process can be implemented on a microcontroller by using a frame buffer to store pixels and sending that data to drive an LCD screen. Data structures, algorithms, and optimization techniques are important considerations for efficient embedded software.

Uploaded by

Ahmed Hamouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

INTRODUCTION TO

SOFTWARE RENDERING ON
EMBEDDED SYSTEMS
AHMED TOLBA
IN THE BEGINNING THERE WERE THE PIXEL
)13-1 ‫في البدأ كان الكلمه ( يوحنا‬
GPU ( GRAPHICS PROCESSING UNIT )

• A GPU is a processor optimized for rendering graphics.


• It only understands certain commands through the Driver that uses an API like DirectX or OpenGL.
• Now there is a new technology that is called GPGPU, which utilizes the GPU for general purpose computation.
• Basic Example is to multiply two matrices, you can use the CPU which is we always called it Software to do the
multiplication, but the CPU is not optimized for multiplying two matrices unless you use SIMD(single instruction multiple
data), which results in a slow computation. You can enhance the speed by using the GPU.
• There is a bottleneck which is system bus and memory that is used by the CPU and GPU, for example you do the
computation on the GPU, and you need back the results in the CPU main memory, the CPU waits (halts) until the GPU
finishes the processing, and copies the data back from the GPU main memory to system Memory.
• Nowadays, there are a lot of asynchronous techniques, new GPU APIs like Vulkan and DirectX 12 which gives a lot of low
level access to the GPU.
ABSTRACT OF SOFTWARE RENDERING
--- RASTERIZATION.

• The process is called Rasterization, remember your raster vector graphics,


it’s an old CRT that raster vectors on the screen, or remember your old
Cathode ray tube TV set ? The process of scan lines that draws the picture is
called rasterization
ABSTRACT PIPELINE OF DRAWING STUFF
ON THE SCREEN
• It starts with pixel.
• From the pixel we can draw lines on the screen
• Using lines we draw triangles, why triangles specifically ?
• A triangle can form a plane in 3D space or 2D space, it can be used to draw polygons very efficiently, you only
need three vertices.
• “ANY” complete 3D model that you see in FIFA or any high quality games is made of thousands of triangles.
• From triangle drawing, we an make it solid, using filling algorithms.
• VIOLA, you got a fully functional GPU.
• We excluded a lot of math like transformation, rendering on the screen using VGA,..etc.
HOW WOULD I ADD GRAPHICS RENDERING
ON MICROCONTROLLER ?
• Usually most LCD kits provides a driver for driving the microcontroller on the LCD.
• From that step, you can draw pixels on the LCD screen.
• Some LCD screens holds what they called a Frame buffer.
• A Frame buffer is a piece of memory that holds your pixels off screen, then the microcontroller just rasterize that
frame buffer linearly to draw the pixels on the screen, so basically an FPGA implementation of GPU always
include a frame buffer for drawing to it, then we can scan that piece of memory and render the contents of an
image. This is sometimes called an offline rendering, without the need of any memory from your
microcontrollers side.
• Can we add a frame buffer to the microcontroller so that we render the contents to it then give that contents to the
LCD controller ? Yes we can, and it avoids something called Flickering when rendering animation.
LINE DRAWING ALGORITHMS
A line connects two points. It is a basic element in graphics.
To draw a line, you need two points between which you can draw a line.
DDA Algorithm
Digital Differential Analyzer (DDA) algorithm is the simple line generation
algorithm which is explained step by step here.
STEPS FOR DDA

• From high school, we know the equation y = mx + c, m is slope, c is the intercept.


• Two points define a line (x0,y0), (x1,y1)
• Calculate the deltas, dx = x1 – x0, dy = y1 – y2
• If dx > dy then you need more steps in in x coordinate
• If (std::abs(dx) > std::abs(dy)) steps = absolute(dx) else steps = absolute(dy)
• Xincrement = dx / (float) steps, Yincrement = dy / (float)steps
• For each step x = x+Xincrement; y = y + Yincrement; renderpixel(x,y, Color );
• Disadvantge, there is no Floating Point on most microcontrollers, so drawing 1M pixels is a disaster on a microcontroller, most
microcontrollers that doesn’t have an FPU, it simulates the floating point calculation using software method.
• Another method which uses just integer coordinates is devise by Bresnham, which obviously a great optimization on CPUs and
microcontrollers.
THEN AFTER DRAWING LINES ?

• We can draw triangles, and we let them solid.


• Solid filling is simply making the triangle solid.
• A simple method is to just calculate the slopes of the two sides and
incremently draw a line between the deltas of both sides.
AFTER DRAWING LINES, TRIANGLES ?

• To draw a cube we need for each face two triangles.


• Cube is the hello world of Graphics programming, if you are able to draw a
cube, you can use it to draw 3D model on the LCD screen.
THEN YOU HAVE A GPU

• Things that are left like transformation, it’s basically a 3D mathematical models of
transforming the vertices from local coordinates to world coordinates.
• A lot of matrices are involved, multiplication,..etc
• Microcontrollers are not supported for these purposes, usually as I said in modern mobile
phones, there is a dedicated GPU for that purpose.
• But you can do fully 3D Graphics on new generation of ARM Cortex series.
• They have full hardware implementation for DSP thinness like matrix multiplications,
calculating fast Fourier transform, they even have FPUs!.
IMPORTANT STUFF NOT RELATED TO
SESSION
• There are few things that I need to talk about to become a very good embedded software engineer.
• Know your hardware and its capabilities.
• Lets talk about State Machines, Data Structure and algorithms, whey they are important in
embedded software.
• Usually any CS guy is proficient in those stuff, they study automata, deterministic, not
deterministic machines, petri nets,..etc.
• They know more about Data structures and algorithms, their complexities, how to use a specific
algorithm in certain problem.
DATA STRUCTURES AND ALGORITHMS

• A recursive function, is a function that calls itself.


• Never use it on an embedded systems.
• Usually it uses a stack to keep a copy of local variables and the parameters that are passed to the function.
• A stack is a piece of memory that is allocated, it has a very limited size, usually constrained by the main
memory on the microcontroller
• A recursion from its nature, it creates local copy of those function stuff, and it will explode the stack.
• Simple example of recursion is calculating factorial, F(3) = 3*f(2) = 3 * 2 * F(1) = 3*2*1=6
DATA STRUCTURE AND ALGORITHMS

• A queue is a first in first out data structure..


• Why would we need it ?
• Suppose you’re using your serial port for sending and transmitting data from the TX to the RX and vice versa
• What if the Rx lost the connection to the TX…
• What does youtube do ? It buffers the data, it uses a circular queue for that purpose.. It keep adding the data to
the queue, when it loses the connection, it resumes, and be able to continue from the “LAST” packet, byte that
is received.
• Suppose for example you are sending an image through the serial port, what if the connection is lost, should not
be cool to continue resuming from the last byte that the bitmap has ?
DATA STRUCTURE AND ALGORITHMS

• Binary search, suppose you have a dictionary and you want to search for a word.. You open in the
middle and look for that word, if it’s on the left, then you got to the middle, and check if the word is
the middle element, if its not then it should be in the right part, you continue that process…
• Complexity in terms of time is O Log N, you keep dividing the problem into two.
• A Constraint, the data should be sorted to look for items. (1,2,3,9,11)… search for 3 in that list..
• Suppose you have a phone book embedded system, and you have million of items.. And you need to
search for name Ahmed.. If the data is not sorted you need to make a loop that has 1M counts, and you
keep checking in the name Ahmed is in the list or not.
• By sorting the data and using binary search, you can optimize the time complexity to LOG 1M
DATA STRUCTURE AND ALGORITHMS

• As we have seen sorting data is useful in cases like we mentioned.


• There are a lot of sorting algorithms, bubble sort, insertion sort, selection
sort, quicksort, merge, both use recursion, be aware of that.
• Most sorting algorithms are in time complexity of O N*Log N.
REFERENCES FOR ALGORITHMS AND DATA
STRUCTURES

• Introduction to Algorithms by Cormen CLRS


• Algorithms by Robert Sedgwick
OPTIMIZATION TECHNIQUES

• Look up tables
• Build a table of pre-calculated values of sin and cos
• Useful for rotating a point in 2D, or calculating distances between two GPS points.
• Unrolling the loop, a simple loop is constructed by comparison, increment and jump
• If the body of the loop is simple, you can unroll the loop, or if you are doing heavily calculations inside
the body of the loop then there is no need to unroll the loop.
• Fixed point math is emulating the floating point arithmetics using integers
• Most microcontrollers don’t have FPUs, it’s very useful to use fixed point math instead of simulated
floating points that are done by the compiler.
QUESTION RELATED TO THE SESSION
OPEN QUESTIONS
MANY THANKS!

You might also like