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_top.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
TOP 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
module gfx_top (wb_clk_i, wb_rst_i, wb_inta_o,
25
  // Wishbone master signals (interfaces with video memory, write)
26
  wbm_write_cyc_o, wbm_write_stb_o, wbm_write_cti_o, wbm_write_bte_o, wbm_write_we_o, wbm_write_adr_o, wbm_write_sel_o, wbm_write_ack_i, wbm_write_err_i, wbm_write_dat_o,
27
  // Wishbone master signals (interfaces with video memory, read)
28
  wbm_read_cyc_o, wbm_read_stb_o, wbm_read_cti_o, wbm_read_bte_o, wbm_read_we_o, wbm_read_adr_o, wbm_read_sel_o, wbm_read_ack_i, wbm_read_err_i, wbm_read_dat_i,
29
  // Wishbone slave signals (interfaces with main bus/CPU)
30
  wbs_cyc_i, wbs_stb_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_adr_i, wbs_sel_i, wbs_ack_o, wbs_err_o, wbs_dat_i, wbs_dat_o
31
);
32
 
33
// Set default parameters
34
parameter point_width    = 16;
35
parameter subpixel_width = 16;
36
parameter fifo_depth     = 10;
37
 
38
parameter REG_ADR_HIBIT = 9;
39
 
40
// Common wishbone signals
41
input         wb_clk_i;    // master clock input
42
input         wb_rst_i;    // Asynchronous active high reset
43
output        wb_inta_o;   // interrupt
44
 
45
// Wishbone master signals (write)
46
output        wbm_write_cyc_o;    // cycle output
47
output        wbm_write_stb_o;    // strobe output
48
output [ 2:0] wbm_write_cti_o;    // cycle type id
49
output [ 1:0] wbm_write_bte_o;    // burst type extension
50
output        wbm_write_we_o;     // write enable output
51
output [31:0] wbm_write_adr_o;    // address output
52
output [ 3:0] wbm_write_sel_o;    // byte select outputs (only 32bits accesses are supported)
53
input         wbm_write_ack_i;    // wishbone cycle acknowledge
54
input         wbm_write_err_i;    // wishbone cycle error
55
output [31:0] wbm_write_dat_o;    // wishbone data out
56
 
57
// Wishbone master signals (read)
58
output        wbm_read_cyc_o;    // cycle output
59
output        wbm_read_stb_o;    // strobe output
60
output [ 2:0] wbm_read_cti_o;    // cycle type id
61
output [ 1:0] wbm_read_bte_o;    // burst type extension
62
output        wbm_read_we_o;     // write enable output
63
output [31:0] wbm_read_adr_o;    // address output
64
output [ 3:0] wbm_read_sel_o;    // byte select outputs (only 32bits accesses are supported)
65
input         wbm_read_ack_i;    // wishbone cycle acknowledge
66
input         wbm_read_err_i;    // wishbone cycle error
67
input  [31:0] wbm_read_dat_i;    // wishbone data in
68
 
69
// Wishbone slave signals
70
input         wbs_cyc_i;    // cycle input
71
input         wbs_stb_i;    // strobe input
72
input  [ 2:0] wbs_cti_i;    // cycle type id
73
input  [ 1:0] wbs_bte_i;    // burst type extension
74
input         wbs_we_i;     // write enable input
75
input  [31:0] wbs_adr_i;    // address input
76
input  [ 3:0] wbs_sel_i;    // byte select input (only 32bits accesses are supported)
77
output        wbs_ack_o;    // wishbone cycle acknowledge
78
output        wbs_err_o;    // wishbone cycle error
79
input  [31:0] wbs_dat_i;    // wishbone data in
80
output [31:0] wbs_dat_o;    // wishbone data out
81
 
82
// Wires and variables
83
 
84
wire wbmwriter_sint; // connect to slave interface
85
wire wbmreader_sint;
86
 
87
wire vector_wbs_ack;
88
wire transform_wbs_ack;
89
 
90
wire            [31:2] target_base_reg;
91
wire [point_width-1:0] target_size_x_reg;
92
wire [point_width-1:0] target_size_y_reg;
93
 
94
wire            [31:2] wbs_fragment_tex0_base;
95
wire [point_width-1:0] wbs_fragment_tex0_size_x;
96
wire [point_width-1:0] wbs_fragment_tex0_size_y;
97
 
98
wire [31:2] render_wbmwriter_addr;
99
wire  [3:0] render_wbmwriter_sel;
100
wire [31:0] render_wbmwriter_dat;
101
 
102
wire [1:0] color_depth_reg;
103
 
104
wire render_wbmwriter_memory_pixel_write;
105
wire wbs_raster_rect_write;
106
wire wbs_raster_line_write;
107
wire wbs_raster_triangle_write;
108
wire wbs_raster_interpolate;
109
 
110
wire wbs_fragment_curve_write;
111
 
112
wire wbmwriter_render_ack;
113
 
114
// src pixel
115
wire [point_width-1:0] wbs_raster_src_pixel0_x;
116
wire [point_width-1:0] wbs_raster_src_pixel0_y;
117
wire [point_width-1:0] wbs_raster_src_pixel1_x;
118
wire [point_width-1:0] wbs_raster_src_pixel1_y;
119
 
120
// dest pixel
121
wire signed [point_width-1:-subpixel_width] wbs_transform_dest_pixel_x;
122
wire signed [point_width-1:-subpixel_width] wbs_transform_dest_pixel_y;
123
wire signed [point_width-1:-subpixel_width] wbs_transform_dest_pixel_z;
124
wire                           [1:0] wbs_transform_dest_pixel_id;
125
 
126
// transformation matrix
127
wire signed [point_width-1:-subpixel_width] wbs_transform_aa;
128
wire signed [point_width-1:-subpixel_width] wbs_transform_ab;
129
wire signed [point_width-1:-subpixel_width] wbs_transform_ac;
130
wire signed [point_width-1:-subpixel_width] wbs_transform_tx;
131
wire signed [point_width-1:-subpixel_width] wbs_transform_ba;
132
wire signed [point_width-1:-subpixel_width] wbs_transform_bb;
133
wire signed [point_width-1:-subpixel_width] wbs_transform_bc;
134
wire signed [point_width-1:-subpixel_width] wbs_transform_ty;
135
wire signed [point_width-1:-subpixel_width] wbs_transform_ca;
136
wire signed [point_width-1:-subpixel_width] wbs_transform_cb;
137
wire signed [point_width-1:-subpixel_width] wbs_transform_cc;
138
wire signed [point_width-1:-subpixel_width] wbs_transform_tz;
139
 
140
// clip pixel
141
wire [point_width-1:0] clip_pixel0_x_reg;
142
wire [point_width-1:0] clip_pixel0_y_reg;
143
wire [point_width-1:0] clip_pixel1_x_reg;
144
wire [point_width-1:0] clip_pixel1_y_reg;
145
 
146
wire [31:0] color0_reg;
147
wire [31:0] color1_reg;
148
wire [31:0] color2_reg;
149
 
150
wire [point_width-1:0] u0_reg;
151
wire [point_width-1:0] v0_reg;
152
wire [point_width-1:0] u1_reg;
153
wire [point_width-1:0] v1_reg;
154
wire [point_width-1:0] u2_reg;
155
wire [point_width-1:0] v2_reg;
156
 
157
wire [7:0] alpha0_reg;
158
wire [7:0] alpha1_reg;
159
wire [7:0] alpha2_reg;
160
 
161
wire texture_enable_reg;
162
 
163
wire        blending_enable_reg;
164
wire  [7:0] global_alpha_reg;
165
wire        colorkey_enable_reg;
166
wire [31:0] colorkey_reg;
167
wire        clipping_enable_reg;
168
wire        inside_reg;
169
wire        zbuffer_enable_reg;
170
wire [31:2] zbuffer_base_reg;
171
 
172
wire        wbs_transform_transform;
173
wire        wbs_transform_forward;
174
 
175
wire        raster_wbs_ack;
176
 
177
// Slave wishbone interface. Reads wishbone bus and fills registers
178
gfx_wbs wb_databus(
179
  .clk_i             (wb_clk_i),
180
  .rst_i             (wb_rst_i),
181
  .adr_i             (wbs_adr_i[REG_ADR_HIBIT:0]),
182
  .dat_i             (wbs_dat_i),
183
  .dat_o             (wbs_dat_o),
184
  .sel_i             (wbs_sel_i),
185
  .we_i              (wbs_we_i),
186
  .stb_i             (wbs_stb_i),
187
  .cyc_i             (wbs_cyc_i),
188
  .ack_o             (wbs_ack_o),
189
  .rty_o             (),
190
  .err_o             (wbs_err_o),
191
  .inta_o            (wb_inta_o),
192
 
193
  //source pixel
194
  .src_pixel0_x_o    (wbs_raster_src_pixel0_x),
195
  .src_pixel0_y_o    (wbs_raster_src_pixel0_y),
196
  .src_pixel1_x_o    (wbs_raster_src_pixel1_x),
197
  .src_pixel1_y_o    (wbs_raster_src_pixel1_y),
198
  //destination pixel
199
  .dest_pixel_x_o    (wbs_transform_dest_pixel_x),
200
  .dest_pixel_y_o    (wbs_transform_dest_pixel_y),
201
  .dest_pixel_z_o    (wbs_transform_dest_pixel_z),
202
  .dest_pixel_id_o   (wbs_transform_dest_pixel_id),
203
  //matrix
204
  .aa_o              (wbs_transform_aa),
205
  .ab_o              (wbs_transform_ab),
206
  .ac_o              (wbs_transform_ac),
207
  .tx_o              (wbs_transform_tx),
208
  .ba_o              (wbs_transform_ba),
209
  .bb_o              (wbs_transform_bb),
210
  .bc_o              (wbs_transform_bc),
211
  .ty_o              (wbs_transform_ty),
212
  .ca_o              (wbs_transform_ca),
213
  .cb_o              (wbs_transform_cb),
214
  .cc_o              (wbs_transform_cc),
215
  .tz_o              (wbs_transform_tz),
216
  .transform_point_o (wbs_transform_transform),
217
  .forward_point_o   (wbs_transform_forward),
218
  //clip pixel
219
  .clip_pixel0_x_o   (clip_pixel0_x_reg),
220
  .clip_pixel0_y_o   (clip_pixel0_y_reg),
221
  .clip_pixel1_x_o   (clip_pixel1_x_reg),
222
  .clip_pixel1_y_o   (clip_pixel1_y_reg),
223
 
224
  .color0_o          (color0_reg),
225
  .color1_o          (color1_reg),
226
  .color2_o          (color2_reg),
227
 
228
  .u0_o              (u0_reg),
229
  .v0_o              (v0_reg),
230
  .u1_o              (u1_reg),
231
  .v1_o              (v1_reg),
232
  .u2_o              (u2_reg),
233
  .v2_o              (v2_reg),
234
 
235
  .a0_o              (alpha0_reg),
236
  .a1_o              (alpha1_reg),
237
  .a2_o              (alpha2_reg),
238
  .global_alpha_o    (global_alpha_reg),
239
 
240
  .target_base_o     (target_base_reg),
241
  .target_size_x_o   (target_size_x_reg),
242
  .target_size_y_o   (target_size_y_reg),
243
  .tex0_base_o       (wbs_fragment_tex0_base),
244
  .tex0_size_x_o     (wbs_fragment_tex0_size_x),
245
  .tex0_size_y_o     (wbs_fragment_tex0_size_y),
246
 
247
  .color_depth_o     (color_depth_reg),
248
 
249
  .rect_write_o      (wbs_raster_rect_write),
250
  .line_write_o      (wbs_raster_line_write),
251
  .triangle_write_o  (wbs_raster_triangle_write),
252
  .curve_write_o     (wbs_fragment_curve_write),
253
  .interpolate_o     (wbs_raster_interpolate),
254
 
255
  .writer_sint_i     (wbmwriter_sint),
256
  .reader_sint_i     (wbmreader_sint),
257
 
258
  .pipeline_ack_i    (raster_wbs_ack),
259
  .transform_ack_i   (transform_wbs_ack),
260
 
261
  .texture_enable_o  (texture_enable_reg),
262
  .blending_enable_o (blending_enable_reg),
263
  .colorkey_enable_o (colorkey_enable_reg),
264
  .colorkey_o        (colorkey_reg),
265
  .clipping_enable_o (clipping_enable_reg),
266
  .inside_o          (inside_reg),
267
  .zbuffer_enable_o  (zbuffer_enable_reg),
268
  .zbuffer_base_o    (zbuffer_base_reg)
269
  );
270
 
271
defparam wb_databus.point_width    = point_width;
272
defparam wb_databus.subpixel_width = subpixel_width;
273
defparam wb_databus.fifo_depth     = fifo_depth;
274
defparam wb_databus.REG_ADR_HIBIT  = REG_ADR_HIBIT;
275
 
276
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel0_x;
277
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel0_y;
278
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel1_x;
279
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel1_y;
280
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel2_x;
281
wire signed [point_width-1:-subpixel_width] transform_raster_dest_pixel2_y;
282
 
283
wire signed [point_width-1:0] transform_cuvz_dest_pixel0_z;
284
wire signed [point_width-1:0] transform_cuvz_dest_pixel1_z;
285
wire signed [point_width-1:0] transform_cuvz_dest_pixel2_z;
286
 
287
// Apply transforms to points
288
gfx_transform transform(
289
.clk_i           (wb_clk_i),
290
.rst_i           (wb_rst_i),
291
.x_i             (wbs_transform_dest_pixel_x),
292
.y_i             (wbs_transform_dest_pixel_y),
293
.z_i             (wbs_transform_dest_pixel_z),
294
.point_id_i      (wbs_transform_dest_pixel_id),
295
// Matrix
296
.aa              (wbs_transform_aa),
297
.ab              (wbs_transform_ab),
298
.ac              (wbs_transform_ac),
299
.tx              (wbs_transform_tx),
300
.ba              (wbs_transform_ba),
301
.bb              (wbs_transform_bb),
302
.bc              (wbs_transform_bc),
303
.ty              (wbs_transform_ty),
304
.ca              (wbs_transform_ca),
305
.cb              (wbs_transform_cb),
306
.cc              (wbs_transform_cc),
307
.tz              (wbs_transform_tz),
308
// Output points
309
.p0_x_o          (transform_raster_dest_pixel0_x),
310
.p0_y_o          (transform_raster_dest_pixel0_y),
311
.p0_z_o          (transform_cuvz_dest_pixel0_z),
312
.p1_x_o          (transform_raster_dest_pixel1_x),
313
.p1_y_o          (transform_raster_dest_pixel1_y),
314
.p1_z_o          (transform_cuvz_dest_pixel1_z),
315
.p2_x_o          (transform_raster_dest_pixel2_x),
316
.p2_y_o          (transform_raster_dest_pixel2_y),
317
.p2_z_o          (transform_cuvz_dest_pixel2_z),
318
.transform_i     (wbs_transform_transform),
319
.forward_i       (wbs_transform_forward),
320
.ack_o           (transform_wbs_ack)
321
);
322
 
323
defparam transform.point_width = point_width;
324
defparam transform.subpixel_width = subpixel_width;
325
 
326
wire raster_clip_write;
327
wire [point_width-1:0] raster_x_pixel;
328
wire [point_width-1:0] raster_y_pixel;
329
wire clip_ack;
330
wire raster_interp_write;
331
wire interp_raster_ack;
332
wire [point_width-1:0] raster_clip_u;
333
wire [point_width-1:0] raster_clip_v;
334
 
335
wire [2*point_width-1:0] raster_interp_edge0;
336
wire [2*point_width-1:0] raster_interp_edge1;
337
wire [2*point_width-1:0] raster_interp_area;
338
 
339
// Rasterizer generates pixels to calculate
340
gfx_rasterizer rasterizer0 (
341
  .clk_i            (wb_clk_i),
342
  .rst_i            (wb_rst_i),
343
 
344
  .clip_ack_i       (clip_ack),
345
  .interp_ack_i     (interp_raster_ack),
346
  .ack_o            (raster_wbs_ack),
347
 
348
  .rect_write_i     (wbs_raster_rect_write),
349
  .line_write_i     (wbs_raster_line_write),
350
  .triangle_write_i (wbs_raster_triangle_write),
351
  .interpolate_i    (wbs_raster_interpolate),
352
 
353
  .texture_enable_i (texture_enable_reg),
354
  // source pixel coordinates
355
  .src_pixel0_x_i   (wbs_raster_src_pixel0_x),
356
  .src_pixel0_y_i   (wbs_raster_src_pixel0_y),
357
  .src_pixel1_x_i   (wbs_raster_src_pixel1_x),
358
  .src_pixel1_y_i   (wbs_raster_src_pixel1_y),
359
 
360
  // destination pixel coordinates
361
  .dest_pixel0_x_i  (transform_raster_dest_pixel0_x),
362
  .dest_pixel0_y_i  (transform_raster_dest_pixel0_y),
363
  .dest_pixel1_x_i  (transform_raster_dest_pixel1_x),
364
  .dest_pixel1_y_i  (transform_raster_dest_pixel1_y),
365
  .dest_pixel2_x_i  (transform_raster_dest_pixel2_x),
366
  .dest_pixel2_y_i  (transform_raster_dest_pixel2_y),
367
 
368
  // clip pixel coordinates
369
  .clipping_enable_i       (clipping_enable_reg),
370
  .clip_pixel0_x_i         (clip_pixel0_x_reg),
371
  .clip_pixel0_y_i         (clip_pixel0_y_reg),
372
  .clip_pixel1_x_i         (clip_pixel1_x_reg),
373
  .clip_pixel1_y_i         (clip_pixel1_y_reg),
374
 
375
  // Screen size
376
  .target_size_x_i  (target_size_x_reg),
377
  .target_size_y_i  (target_size_y_reg),
378
 
379
  // Output pixel
380
  .x_counter_o      (raster_x_pixel),
381
  .y_counter_o      (raster_y_pixel),
382
  .u_o              (raster_clip_u),
383
  .v_o              (raster_clip_v),
384
  .clip_write_o     (raster_clip_write),
385
  // To interp
386
  .triangle_edge0_o (raster_interp_edge0),
387
  .triangle_edge1_o (raster_interp_edge1),
388
  .triangle_area_o  (raster_interp_area),
389
  .interp_write_o   (raster_interp_write)
390
  );
391
 
392
defparam rasterizer0.point_width = point_width;
393
defparam rasterizer0.subpixel_width = subpixel_width;
394
defparam rasterizer0.delay_width  = 5; // log2(point_width+1)
395
 
396
wire [point_width-1:0] interp_cuvz_x;
397
wire [point_width-1:0] interp_cuvz_y;
398
 
399
wire [point_width-1:0] interp_cuvz_factor0;
400
wire [point_width-1:0] interp_cuvz_factor1;
401
 
402
wire                   interp_cuvz_write;
403
 
404
wire                   cuvz_interp_ack;
405
 
406
gfx_interp interp(
407
.clk_i     (wb_clk_i),
408
.rst_i     (wb_rst_i),
409
.ack_i     (cuvz_interp_ack),
410
.ack_o     (interp_raster_ack),
411
.write_i   (raster_interp_write),
412
.edge0_i   (raster_interp_edge0),
413
.edge1_i   (raster_interp_edge1),
414
.area_i    (raster_interp_area),
415
.x_i       (raster_x_pixel),
416
.y_i       (raster_y_pixel),
417
.x_o       (interp_cuvz_x),
418
.y_o       (interp_cuvz_y),
419
.factor0_o (interp_cuvz_factor0),
420
.factor1_o (interp_cuvz_factor1),
421
.write_o   (interp_cuvz_write)
422
);
423
 
424
defparam interp.point_width  = point_width;
425
defparam interp.delay_width  = 5; // log2(point_width+1)
426
defparam interp.result_width = 4; // 16 pipeline slots
427
 
428
wire [point_width-1:0] cuvz_clip_x;
429
wire [point_width-1:0] cuvz_clip_y;
430
wire signed [point_width-1:0] cuvz_clip_z;
431
wire [point_width-1:0] cuvz_clip_u;
432
wire [point_width-1:0] cuvz_clip_v;
433
wire             [7:0] cuvz_clip_alpha;
434
wire [point_width-1:0] cuvz_clip_bezier_factor0;
435
wire [point_width-1:0] cuvz_clip_bezier_factor1;
436
wire                   cuvz_clip_write;
437
 
438
wire            [31:0] cuvz_clip_color;
439
 
440
gfx_cuvz cuvz(
441
.clk_i     (wb_clk_i),
442
.rst_i     (wb_rst_i),
443
.ack_i     (clip_ack),
444
.ack_o     (cuvz_interp_ack),
445
.write_i   (interp_cuvz_write),
446
// Variables needed for interpolation
447
.factor0_i (interp_cuvz_factor0),
448
.factor1_i (interp_cuvz_factor1),
449
// Color
450
.color0_i  (color0_reg),
451
.color1_i  (color1_reg),
452
.color2_i  (color2_reg),
453
.color_depth_i (color_depth_reg),
454
.color_o   (cuvz_clip_color),
455
// Depth
456
.z0_i      (transform_cuvz_dest_pixel0_z),
457
.z1_i      (transform_cuvz_dest_pixel1_z),
458
.z2_i      (transform_cuvz_dest_pixel2_z),
459
.z_o       (cuvz_clip_z),
460
// Alpha
461
.a0_i      (alpha0_reg),
462
.a1_i      (alpha1_reg),
463
.a2_i      (alpha2_reg),
464
.a_o       (cuvz_clip_alpha),
465
// Texture coordinates
466
.u0_i      (u0_reg),
467
.v0_i      (v0_reg),
468
.u1_i      (u1_reg),
469
.v1_i      (v1_reg),
470
.u2_i      (u2_reg),
471
.v2_i      (v2_reg),
472
.u_o       (cuvz_clip_u),
473
.v_o       (cuvz_clip_v),
474
// Bezier calculations
475
.bezier_factor0_o (cuvz_clip_bezier_factor0),
476
.bezier_factor1_o (cuvz_clip_bezier_factor1),
477
// Raster position
478
.x_i       (interp_cuvz_x),
479
.y_i       (interp_cuvz_y),
480
.x_o       (cuvz_clip_x),
481
.y_o       (cuvz_clip_y),
482
 
483
.write_o   (cuvz_clip_write)
484
);
485
 
486
defparam cuvz.point_width     = point_width;
487
 
488
wire                   clip_fragment_write_enable;
489
wire [point_width-1:0] clip_fragment_x_pixel;
490
wire [point_width-1:0] clip_fragment_y_pixel;
491
wire signed [point_width-1:0] clip_fragment_z_pixel;
492
wire                   fragment_clip_ack;
493
wire [point_width-1:0] clip_fragment_u;
494
wire [point_width-1:0] clip_fragment_v;
495
wire             [7:0] clip_fragment_a;
496
wire [point_width-1:0] clip_fragment_bezier_factor0;
497
wire [point_width-1:0] clip_fragment_bezier_factor1;
498
 
499
wire            [31:0] clip_fragment_color;
500
 
501
wire                   wbmreader_busy;
502
 
503
// Connected through arbiter
504
wire        wbmreader_clip_z_ack;
505
wire [31:2] clip_wbmreader_z_addr;
506
wire [31:0] wbmreader_clip_z_data;
507
wire  [3:0] clip_wbmreader_z_sel;
508
wire        clip_wbmreader_z_request;
509
 
510
// Apply clipping
511
gfx_clip clip(
512
.clk_i            (wb_clk_i),
513
.rst_i            (wb_rst_i),
514
.clipping_enable_i(clipping_enable_reg),
515
.zbuffer_enable_i (zbuffer_enable_reg),
516
.zbuffer_base_i   (zbuffer_base_reg),
517
.target_size_x_i  (target_size_x_reg),
518
.target_size_y_i  (target_size_y_reg),
519
.clip_pixel0_x_i  (clip_pixel0_x_reg),
520
.clip_pixel0_y_i  (clip_pixel0_y_reg),
521
.clip_pixel1_x_i  (clip_pixel1_x_reg),
522
.clip_pixel1_y_i  (clip_pixel1_y_reg),
523
.raster_pixel_x_i (raster_x_pixel),
524
.raster_pixel_y_i (raster_y_pixel),
525
.raster_u_i       (raster_clip_u),
526
.raster_v_i       (raster_clip_v),
527
.flat_color_i     (color0_reg),
528
.raster_write_i   (raster_clip_write),
529
.cuvz_pixel_x_i   (cuvz_clip_x),
530
.cuvz_pixel_y_i   (cuvz_clip_y),
531
.cuvz_pixel_z_i   (cuvz_clip_z),
532
.cuvz_u_i         (cuvz_clip_u),
533
.cuvz_v_i         (cuvz_clip_v),
534
.cuvz_a_i         (cuvz_clip_alpha),
535
.cuvz_color_i     (cuvz_clip_color),
536
.cuvz_write_i     (cuvz_clip_write),
537
.ack_o            (clip_ack),
538
.z_ack_i          (wbmreader_clip_z_ack),
539
.z_addr_o         (clip_wbmreader_z_addr),
540
.z_data_i         (wbmreader_clip_z_data),
541
.z_sel_o          (clip_wbmreader_z_sel),
542
.z_request_o      (clip_wbmreader_z_request),
543
.wbm_busy_i       (wbmreader_busy),
544
.pixel_x_o        (clip_fragment_x_pixel),
545
.pixel_y_o        (clip_fragment_y_pixel),
546
.pixel_z_o        (clip_fragment_z_pixel),
547
.u_o              (clip_fragment_u),
548
.v_o              (clip_fragment_v),
549
.a_o              (clip_fragment_a),
550
.bezier_factor0_i (cuvz_clip_bezier_factor0),
551
.bezier_factor1_i (cuvz_clip_bezier_factor1),
552
.bezier_factor0_o (clip_fragment_bezier_factor0),
553
.bezier_factor1_o (clip_fragment_bezier_factor1),
554
.color_o          (clip_fragment_color),
555
.write_o          (clip_fragment_write_enable),
556
.ack_i            (fragment_clip_ack)
557
);
558
 
559
defparam clip.point_width = point_width;
560
 
561
wire                   fragment_blender_write_enable;
562
wire [point_width-1:0] fragment_blender_x_pixel;
563
wire [point_width-1:0] fragment_blender_y_pixel;
564
wire signed [point_width-1:0] fragment_blender_z_pixel;
565
wire                   blender_fragment_ack;
566
wire            [31:0] fragment_blender_color;
567
wire             [7:0] fragment_blender_alpha;
568
 
569
wire        wbmreader_fragment_texture_ack;
570
wire [31:0] wbmreader_fragment_texture_data;
571
wire [31:2] fragment_wbmreader_texture_addr;
572
wire  [3:0] fragment_wbmreader_texture_sel;
573
wire        fragment_wbmreader_texture_request;
574
 
575
 
576
// Fragment processor generates color of pixel (requires RAM read for textures)
577
gfx_fragment_processor fp0 (
578
  .clk_i             (wb_clk_i),
579
  .rst_i             (wb_rst_i),
580
  .pixel_alpha_i     (clip_fragment_a),
581
  .x_counter_i       (clip_fragment_x_pixel),
582
  .y_counter_i       (clip_fragment_y_pixel),
583
  .z_i               (clip_fragment_z_pixel),
584
  .u_i               (clip_fragment_u),
585
  .v_i               (clip_fragment_v),
586
  .bezier_factor0_i  (clip_fragment_bezier_factor0),
587
  .bezier_factor1_i  (clip_fragment_bezier_factor1),
588
  .bezier_inside_i   (inside_reg),
589
  .ack_i             (blender_fragment_ack),
590
  .write_i           (clip_fragment_write_enable),
591
  .curve_write_i     (wbs_fragment_curve_write),
592
  .pixel_x_o         (fragment_blender_x_pixel),
593
  .pixel_y_o         (fragment_blender_y_pixel),
594
  .pixel_z_o         (fragment_blender_z_pixel),
595
  .pixel_color_i     (clip_fragment_color),
596
  .pixel_color_o     (fragment_blender_color),
597
  .pixel_alpha_o     (fragment_blender_alpha),
598
  .write_o           (fragment_blender_write_enable),
599
  .ack_o             (fragment_clip_ack),
600
  .texture_ack_i     (wbmreader_fragment_texture_ack),
601
  .texture_data_i    (wbmreader_fragment_texture_data),
602
  .texture_addr_o    (fragment_wbmreader_texture_addr),
603
  .texture_sel_o     (fragment_wbmreader_texture_sel),
604
  .texture_request_o (fragment_wbmreader_texture_request),
605
  .texture_enable_i  (texture_enable_reg),
606
  .tex0_base_i       (wbs_fragment_tex0_base),
607
  .tex0_size_x_i     (wbs_fragment_tex0_size_x),
608
  .tex0_size_y_i     (wbs_fragment_tex0_size_y),
609
  .color_depth_i     (color_depth_reg),
610
  .colorkey_enable_i (colorkey_enable_reg),
611
  .colorkey_i        (colorkey_reg)
612
  );
613
 
614
defparam fp0.point_width = point_width;
615
 
616
wire                   blender_render_write_enable;
617
wire [point_width-1:0] blender_render_x_pixel;
618
wire [point_width-1:0] blender_render_y_pixel;
619
wire signed [point_width-1:0] blender_render_z_pixel;
620
wire                   render_blender_ack;
621
wire            [31:0] blender_render_color;
622
 
623
// Connected through arbiter
624
wire        wbmreader_blender_target_ack;
625
wire [31:2] blender_wbmreader_target_addr;
626
wire [31:0] wbmreader_blender_target_data;
627
wire  [3:0] blender_wbmreader_target_sel;
628
wire        blender_wbmreader_target_request;
629
 
630
// Applies alpha blending if enabled (requires RAM read to get target pixel color)
631
// Fragment processor generates color of pixel (requires RAM read for textures)
632
gfx_blender blender0 (
633
  .clk_i            (wb_clk_i),
634
  .rst_i            (wb_rst_i),
635
  .blending_enable_i (blending_enable_reg),
636
  // Render target information
637
  .target_base_i    (target_base_reg),
638
  .target_size_x_i  (target_size_x_reg),
639
  .target_size_y_i  (target_size_y_reg),
640
  .color_depth_i    (color_depth_reg),
641
  .x_counter_i      (fragment_blender_x_pixel),
642
  .y_counter_i      (fragment_blender_y_pixel),
643
  .z_i              (fragment_blender_z_pixel),
644
  .alpha_i          (fragment_blender_alpha),
645
  .global_alpha_i   (global_alpha_reg),
646
  .ack_i            (render_blender_ack),
647
  .target_ack_i     (wbmreader_blender_target_ack),
648
  .target_addr_o    (blender_wbmreader_target_addr),
649
  .target_data_i    (wbmreader_blender_target_data),
650
  .target_sel_o     (blender_wbmreader_target_sel),
651
  .target_request_o (blender_wbmreader_target_request),
652
  .wbm_busy_i       (wbmreader_busy),
653
  .write_i          (fragment_blender_write_enable),
654
  .pixel_x_o        (blender_render_x_pixel),
655
  .pixel_y_o        (blender_render_y_pixel),
656
  .pixel_z_o        (blender_render_z_pixel),
657
  .pixel_color_i    (fragment_blender_color),
658
  .pixel_color_o    (blender_render_color),
659
  .write_o          (blender_render_write_enable),
660
  .ack_o            (blender_fragment_ack)
661
  );
662
 
663
defparam blender0.point_width = point_width;
664
 
665
// Write pixel to target (check for out of bounds)
666
gfx_renderer renderer (
667
  .clk_i           (wb_clk_i),
668
  .rst_i           (wb_rst_i),
669
  // Render target information
670
  .target_base_i   (target_base_reg),
671
  .zbuffer_base_i  (zbuffer_base_reg),
672
  .target_size_x_i (target_size_x_reg),
673
  .target_size_y_i (target_size_y_reg),
674
  .color_depth_i   (color_depth_reg),
675
  // Input pixel
676
  .pixel_x_i       (blender_render_x_pixel),
677
  .pixel_y_i       (blender_render_y_pixel),
678
  .pixel_z_i       (blender_render_z_pixel),
679
  .zbuffer_enable_i(zbuffer_enable_reg),
680
  .color_i         (blender_render_color),
681
 
682
  .render_addr_o   (render_wbmwriter_addr),
683
  .render_sel_o    (render_wbmwriter_sel),
684
  .render_dat_o    (render_wbmwriter_dat),
685
  .ack_o           (render_blender_ack),
686
  .ack_i           (wbmwriter_render_ack),
687
  .write_i         (blender_render_write_enable),
688
  .write_o         (render_wbmwriter_memory_pixel_write)
689
  );
690
 
691
defparam renderer.point_width = point_width;
692
 
693
// Instansiate wishbone master interface (write only)
694
gfx_wbm_write wbm_writer (
695
  .clk_i           (wb_clk_i),
696
  .rst_i           (wb_rst_i),
697
  .cyc_o           (wbm_write_cyc_o),
698
  .stb_o           (wbm_write_stb_o),
699
  .cti_o           (wbm_write_cti_o),
700
  .bte_o           (wbm_write_bte_o),
701
  .we_o            (wbm_write_we_o),
702
  .adr_o           (wbm_write_adr_o),
703
  .sel_o           (wbm_write_sel_o),
704
  .ack_i           (wbm_write_ack_i),
705
  .err_i           (wbm_write_err_i),
706
  .dat_o           (wbm_write_dat_o),
707
  .sint_o          (wbmwriter_sint),
708
 
709
  .write_i         (render_wbmwriter_memory_pixel_write),
710
  .ack_o           (wbmwriter_render_ack),
711
 
712
  // send ack to renderer when done writing to memory.
713
  .render_addr_i   (render_wbmwriter_addr),
714
  .render_sel_i    (render_wbmwriter_sel),
715
  .render_dat_i    (render_wbmwriter_dat)
716
  );
717
 
718
wire        wbmreader_arbiter_ack;
719
wire [31:2] arbiter_wbmreader_addr;
720
wire [31:0] wbmreader_arbiter_data;
721
wire  [3:0] arbiter_wbmreader_sel;
722
wire        arbiter_wbmreader_request;
723
 
724
// Instansiate wbm reader arbiter
725
gfx_wbm_read_arbiter wbm_arbiter (
726
  .master_busy_o     (wbmreader_busy),
727
  // Interface against the wbm read module
728
  .read_request_o    (arbiter_wbmreader_request),
729
  .addr_o            (arbiter_wbmreader_addr),
730
  .sel_o             (arbiter_wbmreader_sel),
731
  .dat_i             (wbmreader_arbiter_data),
732
  .ack_i             (wbmreader_arbiter_ack),
733
  // Interface against masters (clip)
734
  .m0_read_request_i (clip_wbmreader_z_request),
735
  .m0_addr_i         (clip_wbmreader_z_addr),
736
  .m0_sel_i          (clip_wbmreader_z_sel),
737
  .m0_dat_o          (wbmreader_clip_z_data),
738
  .m0_ack_o          (wbmreader_clip_z_ack),
739
  // Interface against masters (fragment processor)
740
  .m1_read_request_i (fragment_wbmreader_texture_request),
741
  .m1_addr_i         (fragment_wbmreader_texture_addr),
742
  .m1_sel_i          (fragment_wbmreader_texture_sel),
743
  .m1_dat_o          (wbmreader_fragment_texture_data),
744
  .m1_ack_o          (wbmreader_fragment_texture_ack),
745
  // Interface against masters (blender)
746
  .m2_read_request_i (blender_wbmreader_target_request),
747
  .m2_addr_i         (blender_wbmreader_target_addr),
748
  .m2_sel_i          (blender_wbmreader_target_sel),
749
  .m2_dat_o          (wbmreader_blender_target_data),
750
  .m2_ack_o          (wbmreader_blender_target_ack)
751
  );
752
 
753
// Instansiate wishbone master interface (read only for textures)
754
gfx_wbm_read wbm_reader (
755
  .clk_i            (wb_clk_i),
756
  .rst_i            (wb_rst_i),
757
  .cyc_o            (wbm_read_cyc_o),
758
  .stb_o            (wbm_read_stb_o),
759
  .cti_o            (wbm_read_cti_o),
760
  .bte_o            (wbm_read_bte_o),
761
  .we_o             (wbm_read_we_o),
762
  .adr_o            (wbm_read_adr_o),
763
  .sel_o            (wbm_read_sel_o),
764
  .ack_i            (wbm_read_ack_i),
765
  .err_i            (wbm_read_err_i),
766
  .dat_i            (wbm_read_dat_i),
767
  .sint_o           (wbmreader_sint),
768
 
769
  // send ack to renderer when done writing to memory.
770
  .read_request_i   (arbiter_wbmreader_request),
771
  .texture_addr_i   (arbiter_wbmreader_addr),
772
  .texture_sel_i    (arbiter_wbmreader_sel),
773
  .texture_dat_o    (wbmreader_arbiter_data),
774
  .texture_data_ack (wbmreader_arbiter_ack)
775
  );
776
 
777
endmodule
778
 

powered by: WebSVN 2.1.0

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