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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_geo.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_geo.v
7
//
8
// Abstract:
9
//   Geometry Engine top module
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
`include "fm_3d_define.v"
43
module fm_geo (
44
  // system
45
  input         clk_core,
46
  input         rst_x,
47
  output        o_debug,
48
  // Vertex Fetch Memory I/F (Read Only)
49 4 specular
(* mark_debug = "true" *)  output        o_req_m,
50
(* mark_debug = "true" *)  output [31:0] o_adrs_m,
51
(* mark_debug = "true" *)  output [2:0]  o_len_m,
52
(* mark_debug = "true" *)  input         i_ack_m,
53
(* mark_debug = "true" *)  input         i_strr_m,
54
(* mark_debug = "true" *)  input  [31:0] i_dbr_m,
55 2 specular
  // Register Configuration
56
  //   vertex fetch
57
  input         i_dma_start,
58
  input  [29:0] i_dma_top_address,
59
  input  [15:0] i_dma_size,
60
  output        o_state,
61
  //   matrix elements  
62
`ifdef D3D_USE_MATRIX_PALETTE
63
  input  [1:0] i_num_mats,
64
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m00,
65
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m01,
66
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m02,
67
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m03,
68
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m10,
69
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m11,
70
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m12,
71
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m13,
72
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m20,
73
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m21,
74
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m22,
75
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m23,
76
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m30,
77
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m31,
78
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m32,
79
  input  [22*`D3D_NUM_OF_MATS-1:0] i_m33,
80
`else
81
  input  [21:0] i_m00,
82
  input  [21:0] i_m01,
83
  input  [21:0] i_m02,
84
  input  [21:0] i_m03,
85
  input  [21:0] i_m10,
86
  input  [21:0] i_m11,
87
  input  [21:0] i_m12,
88
  input  [21:0] i_m13,
89
  input  [21:0] i_m20,
90
  input  [21:0] i_m21,
91
  input  [21:0] i_m22,
92
  input  [21:0] i_m23,
93
  input  [21:0] i_m30,
94
  input  [21:0] i_m31,
95
  input  [21:0] i_m32,
96
  input  [21:0] i_m33,
97
`endif
98
  // viewport mapping
99
  input [21:0]  i_vw,
100
  input [21:0]  i_vh,
101
  // curring
102
  input         i_en_cull,
103
  input         i_ccw,
104
  // Rasterizer I/F
105
  output        o_en,
106
  input         i_ack,
107
  output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
108
  output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
109
  output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
110
  output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
111
  output [`D3D_FTOI_WIDTH-1:0] o_v2_x,
112
  output [`D3D_FTOI_WIDTH-1:0] o_v2_y
113
);
114
 
115
//////////////////////////////////
116
// wire
117
//////////////////////////////////
118
wire        w_en_dma;
119
wire        w_ack_dma;
120
wire [21:0] w_vx_dma;
121
wire [21:0] w_vy_dma;
122
wire [21:0] w_vz_dma;
123
wire [21:0] w_vw_dma;
124
 
125
wire        w_en_mvp;
126
wire        w_ack_mvp;
127
wire [21:0] w_vx_mvp;
128
wire [21:0] w_vy_mvp;
129
wire [21:0] w_vz_mvp;
130
wire [21:0] w_vw_mvp;
131
 
132
wire        w_en_pdiv;
133
wire        w_ack_pdiv;
134
wire [21:0] w_vx_pdiv;
135
wire [21:0] w_vy_pdiv;
136
wire [5:0]  w_outcode_pdiv;
137
 
138
wire w_en_view;
139
wire w_ack_view;
140
wire [21:0] w_vx_view;
141
wire [21:0] w_vy_view;
142
wire [5:0]  w_outcode_view;
143
 
144
`ifdef D3D_USE_CLIP
145 4 specular
(* mark_debug = "true" *) wire w_en_clip;
146
(* mark_debug = "true" *) wire w_ack_clip;
147
(* mark_debug = "true" *) wire [21:0] w_vx_clip;
148
(* mark_debug = "true" *) wire [21:0] w_vy_clip;
149
(* mark_debug = "true" *) wire [21:0] w_vw_clip;
150
(* mark_debug = "true" *) wire [5:0]  w_outcode_clip;
151
(* mark_debug = "true" *) wire w_state_clip;
152 2 specular
`endif
153
 
154
`ifdef D3D_USE_CULL
155
wire w_en_tri;
156
wire w_ack_tri;
157
wire [`D3D_FTOI_WIDTH-1:0] w_v0_x_tri;
158
wire [`D3D_FTOI_WIDTH-1:0] w_v0_y_tri;
159
wire [`D3D_FTOI_WIDTH-1:0] w_v1_x_tri;
160
wire [`D3D_FTOI_WIDTH-1:0] w_v1_y_tri;
161
wire [`D3D_FTOI_WIDTH-1:0] w_v2_x_tri;
162
wire [`D3D_FTOI_WIDTH-1:0] w_v2_y_tri;
163
wire w_state_cull;
164
`endif
165
 
166
wire        w_state_mat;
167
wire        w_state_pd;
168
wire        w_state_view;
169
wire        w_state_if;
170
wire        w_dma_end;
171
 
172
reg [7:0] r_cnt;
173
assign o_debug = (r_cnt == 'd0);
174
assign o_state = w_state_mat &
175
                 w_state_pd &
176
                 w_state_view &
177
                 w_state_if &
178
`ifdef D3D_USE_CLIP
179
                 w_state_clip &
180
`endif
181
`ifdef D3D_USE_CULL
182
                 w_state_cull &
183
`endif
184
                 w_dma_end;
185
 
186
//////////////////////////////////
187
// module instance
188
//////////////////////////////////
189
`ifdef D3D_WISHBONE
190
fm_geo_mem #(.P_BURST_MODE(0)) u_geo_mem (
191
`else
192
fm_geo_mem #(.P_BURST_MODE(1)) u_geo_mem (
193
`endif
194
  // system
195
  .clk_core(clk_core),
196
  .rst_x(rst_x),
197
  // Vertex Fetch Memory I/F (Read Only)
198
  .o_req_m(o_req_m),
199
  .o_adrs_m(o_adrs_m),
200
  .o_len_m(o_len_m),
201
  .i_ack_m(i_ack_m),
202
  .i_strr_m(i_strr_m),
203
  .i_dbr_m(i_dbr_m),
204
  // Register Configuration
205
  //   vertex fetch
206
  .i_dma_start(i_dma_start),
207
  .i_dma_top_address(i_dma_top_address),
208
  .i_dma_size(i_dma_size),
209
  .o_dma_end(w_dma_end),
210
  // vertex output
211
  .o_en(w_en_dma),
212
  .i_ack(w_ack_dma),
213
  .o_vx(w_vx_dma),
214
  .o_vy(w_vy_dma),
215
  .o_vz(w_vz_dma),
216
  .o_vw(w_vw_dma)
217
);
218
 
219
// model-view-projedction matrix
220
fm_geo_matrix u_geo_matrix (
221
  .clk_core(clk_core),
222
  .rst_x(rst_x),
223
  .o_state(w_state_mat),
224
  // vertex input
225
  .i_en(w_en_dma),
226
  .o_ack(w_ack_dma),
227
  .i_vx(w_vx_dma),
228
  .i_vy(w_vy_dma),
229
  .i_vz(w_vz_dma),
230
  .i_vw(w_vw_dma),
231
  // matrix elements
232
`ifdef D3D_USE_MATRIX_PALETTE
233
  .i_num_mats(i_num_mats),
234
`endif
235
  .i_m00(i_m00),
236
  .i_m01(i_m01),
237
  .i_m02(i_m02),
238
  .i_m03(i_m03),
239
  .i_m10(i_m10),
240
  .i_m11(i_m11),
241
  .i_m12(i_m12),
242
  .i_m13(i_m13),
243
  .i_m20(i_m20),
244
  .i_m21(i_m21),
245
  .i_m22(i_m22),
246
  .i_m23(i_m23),
247
  .i_m30(i_m30),
248
  .i_m31(i_m31),
249
  .i_m32(i_m32),
250
  .i_m33(i_m33),
251
  // vertex output
252
  .o_en(w_en_mvp),
253
  .i_ack(w_ack_mvp),
254
  .o_vx(w_vx_mvp),
255
  .o_vy(w_vy_mvp),
256
  .o_vz(w_vz_mvp),
257
  .o_vw(w_vw_mvp)
258
);
259
 
260
`ifdef D3D_USE_CLIP
261
fm_geo_clip u_geo_clip (
262
  .clk_core(clk_core),
263
  .rst_x(rst_x),
264
  .o_state(w_state_clip),
265
  // vertex input
266
  .i_en(w_en_mvp),
267
  .o_ack(w_ack_mvp),
268
  .i_vx(w_vx_mvp),
269
  .i_vy(w_vy_mvp),
270
  .i_vz(w_vz_mvp),
271
  .i_vw(w_vw_mvp),
272
  // vertex output
273
  .o_en(w_en_clip),
274
  .i_ack(w_ack_clip),
275
  .o_outcode(w_outcode_clip),
276
  .o_vx(w_vx_clip),
277
  .o_vy(w_vy_clip),
278
  .o_vw(w_vw_clip)
279
);
280
`endif
281
 
282
// perspective division
283
fm_geo_persdiv u_geo_persdiv (
284
  .clk_core(clk_core),
285
  .rst_x(rst_x),
286
  .o_state(w_state_pd),
287
  // vertex input
288
`ifdef D3D_USE_CLIP
289
  .i_en(w_en_clip),
290
  .o_ack(w_ack_clip),
291
  .i_outcode(w_outcode_clip),
292
  .i_vx(w_vx_clip),
293
  .i_vy(w_vy_clip),
294
  .i_vw(w_vw_clip),
295
`else
296
  .i_en(w_en_mvp),
297
  .o_ack(w_ack_mvp),
298
  .i_outcode(1'b0),
299
  .i_vx(w_vx_mvp),
300
  .i_vy(w_vy_mvp),
301
  .i_vw(w_vw_mvp),
302
`endif
303
  // vertex output 
304
  .o_en(w_en_pdiv),
305
  .i_ack(w_ack_pdiv),
306
  .o_outcode(w_outcode_pdiv),
307
  .o_vx(w_vx_pdiv),
308
  .o_vy(w_vy_pdiv)
309
);
310
 
311
fm_geo_viewport u_geo_viewport (
312
  .clk_core(clk_core),
313
  .rst_x(rst_x),
314
  .o_state(w_state_view),
315
  // register configuration
316
  .i_vw(i_vw),
317
  .i_vh(i_vh),
318
  // vertex input
319
  .i_en(w_en_pdiv),
320
  .o_ack(w_ack_pdiv),
321
  .i_outcode(w_outcode_pdiv),
322
  .i_vx(w_vx_pdiv),
323
  .i_vy(w_vy_pdiv),
324
  // vertex output
325
  .o_en(w_en_view),
326
  .i_ack(w_ack_view),
327
  .o_outcode(w_outcode_view),
328
  .o_vx(w_vx_view),
329
  .o_vy(w_vy_view)
330
);
331
 
332
fm_geo_tri u_geo_tri (
333
  .clk_core(clk_core),
334
  .rst_x(rst_x),
335
  .o_state(w_state_if),
336
  // vertex input
337
  .i_en(w_en_view),
338
  .o_ack(w_ack_view),
339
  .i_outcode(w_outcode_view),
340
  .i_vx(w_vx_view),
341
  .i_vy(w_vy_view),
342
`ifdef D3D_USE_CULL
343
  // vertex output
344
  .o_en(w_en_tri),
345
  .i_ack(w_ack_tri),
346
  .o_v0_x(w_v0_x_tri),
347
  .o_v0_y(w_v0_y_tri),
348
  .o_v1_x(w_v1_x_tri),
349
  .o_v1_y(w_v1_y_tri),
350
  .o_v2_x(w_v2_x_tri),
351
  .o_v2_y(w_v2_y_tri)
352
`else
353
  // vertex output
354
  .o_en(o_en),
355
  .i_ack(i_ack),
356
  .o_v0_x(o_v0_x),
357
  .o_v0_y(o_v0_y),
358
  .o_v1_x(o_v1_x),
359
  .o_v1_y(o_v1_y),
360
  .o_v2_x(o_v2_x),
361
  .o_v2_y(o_v2_y)
362
`endif
363
);
364
 
365
`ifdef D3D_USE_CULL
366
fm_geo_cull u_geo_cull (
367
  // system
368
  .clk_core(clk_core),
369
  .rst_x(rst_x),
370
  // curring
371
  .i_en_cull(i_en_cull),
372
  .i_ccw(i_ccw),
373
  .o_state(w_state_cull),
374
  // triangle input 
375
  .i_en(w_en_tri),
376
  .o_ack(w_ack_tri),
377
  .i_v0_x(w_v0_x_tri),
378
  .i_v0_y(w_v0_y_tri),
379
  .i_v1_x(w_v1_x_tri),
380
  .i_v1_y(w_v1_y_tri),
381
  .i_v2_x(w_v2_x_tri),
382
  .i_v2_y(w_v2_y_tri),
383
  // triangle output
384
  .o_en(o_en),
385
  .i_ack(i_ack),
386
  .o_v0_x(o_v0_x),
387
  .o_v0_y(o_v0_y),
388
  .o_v1_x(o_v1_x),
389
  .o_v1_y(o_v1_y),
390
  .o_v2_x(o_v2_x),
391
  .o_v2_y(o_v2_y)
392
);
393
`endif
394
 
395
`ifdef D3D_SYNC_RESET
396
always @(posedge clk_core) begin
397
`else
398
always @(posedge clk_core or negedge rst_x) begin
399
`endif
400
  if (rst_x == `D3D_RESET_POL) begin
401
   r_cnt <= 'd0;
402
  end else begin
403
  if (w_en_clip & w_ack_clip) begin
404
     if (r_cnt == 'd35) r_cnt <= 'd0;
405
      else r_cnt <= r_cnt + 1'b1;
406
  end
407
  end
408
 
409
end
410
 
411
 
412
endmodule

powered by: WebSVN 2.1.0

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