OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [rtl/] [verilog/] [gfx/] [gfx_transform.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 Orka
/*
2
ORSoC GFX accelerator core
3
Copyright 2012, ORSoC, Per Lenander, Anton Fosselius.
4
 
5
TRANSFORMATION PROCESSING MODULE
6
 
7
 This file is part of orgfx.
8
 
9
 orgfx is free software: you can redistribute it and/or modify
10
 it under the terms of the GNU Lesser General Public License as published by
11
 the Free Software Foundation, either version 3 of the License, or
12
 (at your option) any later version.
13
 
14
 orgfx is distributed in the hope that it will be useful,
15
 but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 GNU Lesser General Public License for more details.
18
 
19
 You should have received a copy of the GNU Lesser General Public License
20
 along with orgfx.  If not, see <http://www.gnu.org/licenses/>.
21
 
22
*/
23
 
24
/*
25
 
26
Input matrix M:
27
    | aa ab ac tx |
28
M = | ba bb bc ty |
29
    | ca cb cc tz |
30
 
31
Input point X:
32
    | x |
33
X = | y |
34
    | z |
35
    | 1 |
36
 
37
Output point X':
38
     | x' |        | aa*x + ab*y + ac*z + tx |
39
X' = | y' | = MX = | ba*x + bb*y + bc*z + ty |
40
     | z' |        | ca*x + cb*y + cc*z + tz |
41
 
42
*/
43
 
44
/* Transforms points with a 4x3 matrix */
45
module gfx_transform(clk_i, rst_i,
46
// Input point
47
x_i, y_i, z_i, point_id_i,
48
// Matrix
49
aa, ab, ac, tx, ba, bb, bc, ty, ca, cb, cc, tz, // TODO: Make signed
50
// Output points
51
p0_x_o, p0_y_o, p0_z_o, p1_x_o, p1_y_o, p1_z_o, p2_x_o, p2_y_o, p2_z_o,
52
transform_i, forward_i,
53
ack_o
54
);
55
 
56
input clk_i;
57
input rst_i;
58
 
59
parameter point_width = 16;
60
parameter subpixel_width = 16;
61
 
62
input signed [point_width-1:-subpixel_width] x_i;
63
input signed [point_width-1:-subpixel_width] y_i;
64
input signed [point_width-1:-subpixel_width] z_i;
65
input                                  [1:0] point_id_i; // point 0,1,2
66
 
67
input signed [point_width-1:-subpixel_width] aa;
68
input signed [point_width-1:-subpixel_width] ab;
69
input signed [point_width-1:-subpixel_width] ac;
70
input signed [point_width-1:-subpixel_width] tx;
71
input signed [point_width-1:-subpixel_width] ba;
72
input signed [point_width-1:-subpixel_width] bb;
73
input signed [point_width-1:-subpixel_width] bc;
74
input signed [point_width-1:-subpixel_width] ty;
75
input signed [point_width-1:-subpixel_width] ca;
76
input signed [point_width-1:-subpixel_width] cb;
77
input signed [point_width-1:-subpixel_width] cc;
78
input signed [point_width-1:-subpixel_width] tz;
79
 
80
output reg signed [point_width-1:-subpixel_width] p0_x_o;
81
output reg signed [point_width-1:-subpixel_width] p0_y_o;
82
output reg signed               [point_width-1:0] p0_z_o;
83
output reg signed [point_width-1:-subpixel_width] p1_x_o;
84
output reg signed [point_width-1:-subpixel_width] p1_y_o;
85
output reg signed               [point_width-1:0] p1_z_o;
86
output reg signed [point_width-1:-subpixel_width] p2_x_o;
87
output reg signed [point_width-1:-subpixel_width] p2_y_o;
88
output reg signed               [point_width-1:0] p2_z_o;
89
 
90
input transform_i, forward_i;
91
 
92
output reg ack_o;
93
 
94
reg [1:0] state;
95
parameter wait_state = 2'b00, forward_state = 2'b01, transform_state = 2'b10;
96
 
97
reg signed [2*point_width-1:-subpixel_width*2] aax;
98
reg signed [2*point_width-1:-subpixel_width*2] aby;
99
reg signed [2*point_width-1:-subpixel_width*2] acz;
100
reg signed [2*point_width-1:-subpixel_width*2] bax;
101
reg signed [2*point_width-1:-subpixel_width*2] bby;
102
reg signed [2*point_width-1:-subpixel_width*2] bcz;
103
reg signed [2*point_width-1:-subpixel_width*2] cax;
104
reg signed [2*point_width-1:-subpixel_width*2] cby;
105
reg signed [2*point_width-1:-subpixel_width*2] ccz;
106
 
107
always @(posedge clk_i or posedge rst_i)
108
if(rst_i)
109
begin
110
  // Initialize registers
111
  ack_o             <= 1'b0;
112
  p0_x_o            <= 1'b0;
113
  p0_y_o            <= 1'b0;
114
  p0_z_o            <= 1'b0;
115
  p1_x_o            <= 1'b0;
116
  p1_y_o            <= 1'b0;
117
  p1_z_o            <= 1'b0;
118
  p2_x_o            <= 1'b0;
119
  p2_y_o            <= 1'b0;
120
  p2_z_o            <= 1'b0;
121
 
122
  aax               <= 1'b0;
123
  aby               <= 1'b0;
124
  acz               <= 1'b0;
125
  bax               <= 1'b0;
126
  bby               <= 1'b0;
127
  bcz               <= 1'b0;
128
  cax               <= 1'b0;
129
  cby               <= 1'b0;
130
  ccz               <= 1'b0;
131
end
132
else
133
  case(state)
134
    wait_state:
135
    begin
136
      ack_o <= 1'b0;
137
 
138
      // Begin transformation
139
      if(transform_i)
140
      begin
141
        aax <= aa * x_i;
142
        aby <= ab * y_i;
143
        acz <= ac * z_i;
144
        bax <= ba * x_i;
145
        bby <= bb * y_i;
146
        bcz <= bc * z_i;
147
        cax <= ca * x_i;
148
        cby <= cb * y_i;
149
        ccz <= cc * z_i;
150
      end
151
      // Forward the point
152
      else if(forward_i)
153
      begin
154
        if(point_id_i == 2'b00)
155
        begin
156
          p0_x_o <= x_i;
157
          p0_y_o <= y_i;
158
          p0_z_o <= z_i[point_width-1:0];
159
        end
160
        else if(point_id_i == 2'b01)
161
        begin
162
          p1_x_o <= x_i;
163
          p1_y_o <= y_i;
164
          p1_z_o <= z_i[point_width-1:0];
165
        end
166
        else if(point_id_i == 2'b10)
167
        begin
168
          p2_x_o <= x_i;
169
          p2_y_o <= y_i;
170
          p2_z_o <= z_i[point_width-1:0];
171
        end
172
      end
173
    end
174
 
175
    forward_state:
176
      ack_o <= 1'b1;
177
 
178
    transform_state:
179
    begin
180
      ack_o <= 1'b1;
181
 
182
      if(point_id_i == 2'b00)
183
        begin
184
          p0_x_o <= x_prime_trunc;
185
          p0_y_o <= y_prime_trunc;
186
          p0_z_o <= z_prime_trunc[point_width-1:0];
187
        end
188
        else if(point_id_i == 2'b01)
189
        begin
190
          p1_x_o <= x_prime_trunc;
191
          p1_y_o <= y_prime_trunc;
192
          p1_z_o <= z_prime_trunc[point_width-1:0];
193
        end
194
        else if(point_id_i == 2'b10)
195
        begin
196
          p2_x_o <= x_prime_trunc;
197
          p2_y_o <= y_prime_trunc;
198
          p2_z_o <= z_prime_trunc[point_width-1:0];
199
        end
200
    end
201
  endcase
202
 
203
wire [subpixel_width-1:0] zeroes = 1'b0;
204
 
205
wire signed [2*point_width-1:-subpixel_width*2] x_prime = aax + aby + acz + {tx,zeroes};
206
wire signed [2*point_width-1:-subpixel_width*2] y_prime = bax + bby + bcz + {ty,zeroes};
207
wire signed [2*point_width-1:-subpixel_width*2] z_prime = cax + cby + ccz + {tz,zeroes};
208
 
209
wire signed [point_width-1:-subpixel_width] x_prime_trunc = x_prime[point_width-1:-subpixel_width];
210
wire signed [point_width-1:-subpixel_width] y_prime_trunc = y_prime[point_width-1:-subpixel_width];
211
wire signed [point_width-1:-subpixel_width] z_prime_trunc = z_prime[point_width-1:-subpixel_width];
212
 
213
// State machine
214
always @(posedge clk_i or posedge rst_i)
215
if(rst_i)
216
  state <= wait_state;
217
else
218
  case(state)
219
    wait_state:
220
      if(transform_i)
221
        state <= transform_state;
222
      else if(forward_i)
223
        state <= forward_state;
224
 
225
    forward_state:
226
      state <= wait_state;
227
 
228
    transform_state:
229
      state <= wait_state;
230
  endcase
231
 
232
endmodule
233
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.