Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mole99 committed Apr 13, 2024
1 parent 179a7eb commit a0df1d8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ The shader has four sources to get input from:
- `X` - X position of the current pixel
- `Y` - Y position of the current pixel
- `TIME` - Increases at 7.5 Hz, before it overflow it counts down again.
- `USER` - Value that can be set via the SPI interface.
- `USER` - Register that can be set via the SPI interface.

### Output

The goal of the shader is to determine the final output color:

- `RGB` - The output color for the current pixel. Channel R, G and B can be set individually.
- `RGB` - The output color for the current pixel. Channel R, G and B can be set individually. If not set, the color of the previous pixel is used.

### Sine Look Up Table

Tiny Shader contains a LUT with 16 6-bit sine values for one quarter of the sine wave. When accesing the LUT, the entries are automatically mirrored to form one half of a sine wave with a total of 32 values.
Tiny Shader contains a LUT with 16 6-bit sine values for a quarter of a sine wave. When accesing the LUT, the entries are automatically mirrored to form one half of a sine wave with a total of 32 6-bit values.

## Instructions

Expand Down Expand Up @@ -85,8 +85,8 @@ The following instructions are supported by Tiny Shader. A program consists of 1
|-----------|---------|-----------|
|AND RA RB|RA <= RA & RB|Boolean AND of RA and RB, result written into RA.|
|OR RA RB|RA <= RA \| RB|Boolean OR of RA and RB, result written into RA.|
|NOT RA RB|RA <= ~RB|Boolean NOT of RB, result written into RA.|
|XOR RA RB|RA <= RA ^ RB|Boolean XOR of RA and RB, result written into RA.|
|NOT RA RB|RA <= ~RB|Invert all bits of RB, result written into RA.|
|XOR RA RB|RA <= RA ^ RB|XOR of RA and RB, result written into RA.|
### Move
|Instruction|Operation|Description|
|-----------|---------|-----------|
Expand Down
108 changes: 105 additions & 3 deletions docs/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,114 @@ You can also include images in this folder and reference them in the markdown. E

## How it works

TODO Explain how your project works
Modern GPUs use fragment shaders to determine the color for each pixel. Thousands of shading units run in parallel to execute a program, the fragment shader, to determine the final color for each pixel.

Tiny Shader mimics such a shading unit, it executes a shader of 10 instructions for each pixel. No framebuffer is used, the color values are generated on the fly. Tiny Shader also offers an SPI interface with which a new shader can be loaded. The final result can be viewed via VGA output.

### Examples

These images and many more can be generated with Tiny Shader. Note, that using the time input the shaders can even be animated.

|Image|Shader|
|-|-|
|![test2.png](images/test2.png)| <pre>GETX R0<br>SINE R1<br>SETR R1<br>GETY R0<br>SINE R1<br>SETG R1</pre> |
|![test4.png](images/test4.png)| <pre>GETX R0<br>GETY R1<br>XOR R0 R1<br>SETRGB R0</pre> |
|![test5.png](images/test5.png)| <pre>GETY R1<br>LDI 1<br>AND R1 R0<br>IFNE R1<br>LDI 63<br>IFEQ R1<br>LDI 0<br>SETRGB R0</pre> |
|![test7.png](images/test7.png)| <pre>CLEAR R3<br>GETX R0<br>GETUSER R1<br>ADD R0 R1<br>SETRGB R0<br>SINE R0<br>HALF R0<br>GETY R1<br>IFGE R1<br>SETRGB R3</pre> |

### Architecture

Tiny Shader has four (mostly) general purpose registers, REG0 to REG4. REG0 is special in a way as it is the target or destination register for some instructions. All registers are 6 bit wide.

#### Input

The shader has four sources to get input from:

- `X` - X position of the current pixel
- `Y` - Y position of the current pixel
- `TIME` - Increases at 7.5 Hz, before it overflow it counts down again.
- `USER` - Register that can be set via the SPI interface.

#### Output

The goal of the shader is to determine the final output color:

- `RGB` - The output color for the current pixel. Channel R, G and B can be set individually. If not set, the color of the previous pixel is used.

#### Sine Look Up Table

Tiny Shader contains a LUT with 16 6-bit sine values for a quarter of a sine wave. When accesing the LUT, the entries are automatically mirrored to form one half of a sine wave with a total of 32 6-bit values.

### Instructions

The following instructions are supported by Tiny Shader. A program consists of 10 instructions and is executed for each pixel individually. The actual resolution is therefore one tenth of the VGA resolution (64x48 pixel).

#### Output
|Instruction|Operation|Description|
|-----------|---------|-----------|
|SETRGB RA|RGB <= RA|Set the output color to the value of the specified register.|
|SETR RA|R <= RA[1:0]|Set the red channel of the output color to the lower two bits of the specified register.|
|SETG RA|G <= RA[1:0]|Set the green channel of the output color to the lower two bits of the specified register.|
|SETB RA|B <= RA[1:0]|Set the blue channel of the output color to the lower two bits of the specified register.|
#### Input
|Instruction|Operation|Description|
|-----------|---------|-----------|
|GETX RA|RA <= X|Set the specified register to the x position of the current pixel.|
|GETY RA|RA <= Y|Set the specified register to the y position of the current pixel.|
|GETTIME RA|RA <= TIME|Set the specified register to the current time value, increases with each frame.|
|GETUSER RA|RA <= USER|Set the specified register to the user value, can be set via the SPI interface.|
#### Branches
|Instruction|Operation|Description|
|-----------|---------|-----------|
|IFEQ RA|TAKE <= RA == REG0|Execute the next instruction if RA equals REG0.|
|IFNE RA|TAKE <= RA != REG0|Execute the next instruction if RA does not equal REG0.|
|IFGE RA|TAKE <= RA >= REG0|Execute the next instruction if RA is greater then or equal REG0.|
|IFLT RA|TAKE <= RA < REG0|Execute the next instruction if RA is less than REG0.|
#### Arithmetic
|Instruction|Operation|Description|
|-----------|---------|-----------|
|DOUBLE RA|RA <= RA * 2|Double the value of RA.|
|HALF RA|RA <= RA / 2|Half the value of RA.|
|ADD RA RB|RA <= RA + RB|Add RA and RB, result written into RA.|
#### Load
|Instruction|Operation|Description|
|-----------|---------|-----------|
|CLEAR RA|RA <= 0|Clear RA by writing 0.|
|LDI IMMEDIATE|RA <= IMMEDIATE|Load an immediate value into RA.|
#### Special
|Instruction|Operation|Description|
|-----------|---------|-----------|
|SINE RA|RA <= SINE[REG0[4:0]]|Get the sine value for REG0 and write into RA. The sine value LUT has 32 entries.|
#### Boolean
|Instruction|Operation|Description|
|-----------|---------|-----------|
|AND RA RB|RA <= RA & RB|Boolean AND of RA and RB, result written into RA.|
|OR RA RB|RA <= RA \| RB|Boolean OR of RA and RB, result written into RA.|
|NOT RA RB|RA <= ~RB|Invert all bits of RB, result written into RA.|
|XOR RA RB|RA <= RA ^ RB|XOR of RA and RB, result written into RA.|
#### Move
|Instruction|Operation|Description|
|-----------|---------|-----------|
|MOV RA RB|RA <= RB|Move value of RB into RA.|
#### Shift
|Instruction|Operation|Description|
|-----------|---------|-----------|
|SHIFTL RA RB|RA <= RA << RB|Shift RA with RB to the left, result written into RA.|
|SHIFTR RA RB|RA <= RA >> RB|Shift RA with RB to the right, result written into RA.|
#### Pseudo
|Instruction|Operation|Description|
|-----------|---------|-----------|
|NOP |R0 <= R0 & R0|No operation.|

## How to test

TODO Explain how to use your project
First set the clock to 25.175 MHz and reset the design. For a simple test, simply connect a Tiny VGA to the output Pmod. A shader is loaded by default should be displayed via VGA.

For advanced features, connect an SPI controller to the bidir pmod. If ui[0], the mode signal, is set to 0, you can write to the user register via SPI. Note that only the last 6 bit are used.

If the mode signal is 1, all bytes transmitted via SPI are shifted into the shader memory. This way you can load a new shader program. Have fun!

## External hardware

TODO List external hardware used in your project (e.g. PMOD, LED display, etc), if any
- [Tiny VGA](https://github.com/mole99/tiny-vga) or similar VGA Pmod
- Optional: SPI controller to write the user register and new shaders

0 comments on commit a0df1d8

Please sign in to comment.