-
Notifications
You must be signed in to change notification settings - Fork 1
/
testbench_rast.sv
318 lines (284 loc) · 7.28 KB
/
testbench_rast.sv
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
module testbench_rast();
timeunit 10ns;
timeprecision 1ns;
logic CLK;
logic RESET;
logic init, start;
logic cont;
logic done;
int prj[4][4];
int scale = (8 * (1<<8));
int pos[3] = '{-25 * (1<<8), 20 * (1<<8), -70 * (1<<8)};
int i = 0;
int f;
// Ava lon slave signals
logic GPU_SLAVE_read;
logic [31:0] GPU_SLAVE_readdata;
logic GPU_SLAVE_write;
logic [31:0] GPU_SLAVE_writedata;
logic [31:0] GPU_SLAVE_address;
logic GPU_SLAVE_chipselect;
// avalon master signal;
logic [31:0] GPU_MASTER_address;
logic GPU_MASTER_read;
logic [31:0] GPU_MASTER_readdata;
logic GPU_MASTER_chipselect;
logic GPU_MASTER_readdatavalid;
logic GPU_MASTER_writeresponsevalid;
logic GPU_MASTER_write;
logic [31:0] GPU_MASTER_writedata;
logic [1:0] GPU_MASTER_response;
logic GPU_MASTER_waitrequest;
int draw_x;
int draw_y;
assign draw_x = (GPU_MASTER_address / 4) % 320;
assign draw_y = (GPU_MASTER_address / 4) / 240;
gpu_core core(
CLK,
RESET,
// Ava lon slave signals
GPU_SLAVE_read,
GPU_SLAVE_readdata,
GPU_SLAVE_write,
GPU_SLAVE_writedata,
GPU_SLAVE_address,
GPU_SLAVE_chipselect,
// avalon master signals
GPU_MASTER_address,
GPU_MASTER_read,
GPU_MASTER_readdata,
GPU_MASTER_chipselect,
GPU_MASTER_readdatavalid,
GPU_MASTER_writeresponsevalid,
GPU_MASTER_write,
GPU_MASTER_writedata,
GPU_MASTER_response,
GPU_MASTER_waitrequest
);
//gen_prj_mat m1(320 * (1<<8), 240* (1<<8), 5*(1<<8), 200*(1<<8), prj);
//rast_cube cube_renderer(CLK, RESET, start, cont,
// scale, '{x, y, z}, prj, rast_ready, rast_rgb, rast_xyz, rast_done);
int v1[3];
int v2[3];
int v3[3];
int xyz[3];
int xyz_f[3];
byte rgb[3];
int verticies[8][3];
assign v1 = verticies[4];
assign v2 = verticies[6];
assign v3 = verticies[7];
logic ready;
byte in_rgb[3] = '{255, 255, 255};
int color_data[240*320*2];
assign rast_done = core.done;
always_ff @ (posedge CLK) begin
if(GPU_MASTER_write)
color_data[GPU_MASTER_address/4] <= GPU_MASTER_writedata;
end
always_comb begin
if(GPU_MASTER_read)
GPU_MASTER_readdata = color_data[GPU_MASTER_address/4];
else
GPU_MASTER_readdata = 32'hxxxx;
end
//rast_triangle test(CLK, RESET, start, cont, v3, v2, v1, in_rgb, draw_ready, rgb, xyz, done);
//project_cube projector(scale, pos, prj, verticies);
assign error = ( (draw_x < 170) | (draw_x > 350) | (draw_y > 427) | (draw_y < 260));
int shift[8][3];
assign xyz_f[0] = core.cube_renderer.triangle_renderer.xyz[0] / (1<<8);
assign xyz_f[1] = core.cube_renderer.triangle_renderer.xyz[1] / (1<<8);
assign xyz_f[2] = core.cube_renderer.triangle_renderer.xyz[2] / (1<<8);
assign shift[0][0] = verticies[0][0] / (1<<8);
assign shift[0][1] = verticies[0][1] / (1<<8);
assign shift[0][2] = verticies[0][2] / (1<<8);
assign shift[1][0] = verticies[1][0] / (1<<8);
assign shift[1][1] = verticies[1][1] / (1<<8);
assign shift[1][2] = verticies[1][2] / (1<<8);
assign shift[2][0] = verticies[2][0] / (1<<8);
assign shift[2][1] = verticies[2][1] / (1<<8);
assign shift[2][2] = verticies[2][2] / (1<<8);
assign shift[3][0] = verticies[3][0] / (1<<8);
assign shift[3][1] = verticies[3][1] / (1<<8);
assign shift[3][2] = verticies[3][2] / (1<<8);
assign shift[4][0] = verticies[4][0] / (1<<8);
assign shift[4][1] = verticies[4][1] / (1<<8);
assign shift[4][2] = verticies[4][2] / (1<<8);
assign shift[5][0] = verticies[5][0] / (1<<8);
assign shift[5][1] = verticies[5][1] / (1<<8);
assign shift[5][2] = verticies[5][2] / (1<<8);
assign shift[6][0] = verticies[6][0] / (1<<8);
assign shift[6][1] = verticies[6][1] / (1<<8);
assign shift[6][2] = verticies[6][2] / (1<<8);
assign shift[7][0] = verticies[7][0] / (1<<8);
assign shift[7][1] = verticies[7][1] / (1<<8);
assign shift[7][2] = verticies[7][2] / (1<<8);
always begin : CLOCK_GENERATION
#1 CLK = ~CLK;
end
initial begin: CLOCK_INITIALIZATION
CLK = 0;
end
initial begin: TEST_VECTORS
// GPU_SLAVE_read,
// [31:0] GPU_SLAVE_readdata,
// GPU_SLAVE_write,
// [31:0] GPU_SLAVE_writedata,
// [31:0] GPU_SLAVE_address,
// GPU_SLAVE_chipselect,
// // avalon master signals
// [31:0] GPU_MASTER_address,
// GPU_MASTER_read,
// [31:0] GPU_MASTER_readdata,
// GPU_MASTER_chipselect,
// GPU_MASTER_readdatavalid,
// GPU_MASTER_writeresponsevalid,
// GPU_MASTER_write,
// [31:0] GPU_MASTER_writedata,
// [1:0] GPU_MASTER_response,
// GPU_MASTER_waitrequest
//
ready = 1;
cont = 0;
start = 0;
GPU_MASTER_writeresponsevalid = 1;
GPU_MASTER_waitrequest = 0;
GPU_MASTER_readdatavalid = 1;
RESET = 0;
#1 RESET = 1;
#2
RESET = 0;
#2
// Set depth buffer pointer
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 3;
GPU_SLAVE_writedata= (320*240*4);
#4
// Set mode to clear depth
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 8;
GPU_SLAVE_writedata= 3;
#4
// Set start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 1;
@(posedge rast_done)
$display("Depth Clear done");
// unSet start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 0;
#4
// unSet done
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 2;
GPU_SLAVE_writedata= 0;
#4
// Set mode to clear frame
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 8;
GPU_SLAVE_writedata= 2;
#4
// Set start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 1;
@(posedge rast_done)
$display("Frame Clear done");
// unSet start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 0;
#4
// unSet done
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 2;
GPU_SLAVE_writedata= 0;
#4
for(int i=-5;i<5;i++) begin
for(int j=-5;j<5;j++) begin
if(j%2 == 0)
continue;
if(i%2 == 0)
continue;
// unSet start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 0;
#4
// unSet done
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 2;
GPU_SLAVE_writedata= 0;
#4
// Set mode to render
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 8;
GPU_SLAVE_writedata= 1;
#4
// Set block id
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 9;
GPU_SLAVE_writedata= $urandom_range(7,0);
#4
// Set scale
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 4;
GPU_SLAVE_writedata= scale;
#4
// Set x
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 5;
GPU_SLAVE_writedata = (0 + (j*scale/(1<<8)) ) * (1<<8);
#4
// Set y
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 6;
GPU_SLAVE_writedata = (0 + ((i+j)*scale/(1<<8)) ) * (1<<8);
#4
// Set z
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 7;
GPU_SLAVE_writedata = (-70 + (i*scale/(1<<8)) ) * (1<<8);
#4
// Set start
GPU_SLAVE_chipselect = 1;
GPU_SLAVE_write = 1;
GPU_SLAVE_address = 1;
GPU_SLAVE_writedata= 1;
#4
GPU_SLAVE_chipselect = 0;
GPU_SLAVE_write = 0;
#4
GPU_MASTER_waitrequest = 0;
GPU_MASTER_writeresponsevalid = 1;
@(posedge rast_done)
$display("Render %d %d Done", i, j);
end
end
$display("Done rendering at time ", $time);
f = $fopen("output.txt","wb+");
for (i = 0; i<(240*320*2); i=i+1)
$fwrite(f,"%h\n",color_data[i]);
$fclose(f);
$display("Done writing to file");
end
endmodule