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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_geo_tri.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_tri.v
7
//
8
// Abstract:
9
//   Construct triangle from vertices.
10
//   divide by 2 x, y after integer convesion
11
//
12
// Author:
13 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
14 2 specular
//
15
//======================================================================
16
//
17
// Copyright (c) 2015, Kenji Ishimaru
18
// All rights reserved.
19
//
20
// Redistribution and use in source and binary forms, with or without
21
// modification, are permitted provided that the following conditions are met:
22
//
23
//  -Redistributions of source code must retain the above copyright notice,
24
//   this list of conditions and the following disclaimer.
25
//  -Redistributions in binary form must reproduce the above copyright notice,
26
//   this list of conditions and the following disclaimer in the documentation
27
//   and/or other materials provided with the distribution.
28
//
29
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
31
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
33
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
36
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
37
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
38
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
//
41
// Revision History
42 4 specular
// Bugfix
43
//   w_all_inside,w_all_outside needs bit reduction
44
//   w_all_inside,w_all_outside needs bit reduction
45 2 specular
 
46
`include "fm_3d_define.v"
47
module fm_geo_tri (
48
  input         clk_core,
49
  input         rst_x,
50
  output        o_state,
51
  // vertex input
52
  input         i_en,
53
  output        o_ack,
54
  input  [5:0]  i_outcode,
55
  input  [21:0] i_vx,
56
  input  [21:0] i_vy,
57
  // vertex output
58
  output        o_en,
59
  input         i_ack,
60
  output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
61
  output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
62
  output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
63
  output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
64
  output [`D3D_FTOI_WIDTH-1:0] o_v2_x,
65
  output [`D3D_FTOI_WIDTH-1:0] o_v2_y
66
);
67
localparam P_V0_X_IN = 'd0;
68
localparam P_V0_Y_IN = 'd1;
69
localparam P_V1_X_IN = 'd2;
70
localparam P_V1_Y_IN = 'd3;
71
localparam P_V2_X_IN = 'd4;
72
localparam P_V2_Y_IN = 'd5;
73
localparam P_DONE    = 'd6;
74
 
75
//////////////////////////////////
76
// regs 
77
//////////////////////////////////
78
reg [2:0]      r_state;
79
reg [21:0]     r_vy;
80
reg [`D3D_FTOI_WIDTH-1:0]     r_v0_x;
81
reg [`D3D_FTOI_WIDTH-1:0]     r_v0_y;
82
reg [`D3D_FTOI_WIDTH-1:0]     r_v1_x;
83
reg [`D3D_FTOI_WIDTH-1:0]     r_v1_y;
84
reg [`D3D_FTOI_WIDTH-1:0]     r_v2_x;
85
reg [`D3D_FTOI_WIDTH-1:0]     r_v2_y;
86
reg [5:0]      r_v0_outcode;
87
reg [5:0]      r_v1_outcode;
88
reg [5:0]      r_v2_outcode;
89
//////////////////////////////////
90
// wire
91
//////////////////////////////////
92
wire [21:0] w_f22_in;
93
wire [15:0] w_i16;
94
 
95
wire        w_set_v0_x;
96
wire        w_set_v0_y;
97
wire        w_set_v1_x;
98
wire        w_set_v1_y;
99
wire        w_set_v2_x;
100
wire        w_set_v2_y;
101
wire        w_set_y;
102
wire        w_all_inside;
103
wire        w_all_outside;
104
wire        w_z_outside;
105
wire        w_tri_outside;
106
 
107
//////////////////////////////////
108
// assign
109
//////////////////////////////////
110
assign o_state = (r_state == P_V0_X_IN);
111
assign o_v0_x = r_v0_x;
112
assign o_v0_y = r_v0_y;
113
assign o_v1_x = r_v1_x;
114
assign o_v1_y = r_v1_y;
115
assign o_v2_x = r_v2_x;
116
assign o_v2_y = r_v2_y;
117
assign o_ack = (r_state == P_V0_X_IN) |
118
              (r_state == P_V1_X_IN) |
119
              (r_state == P_V2_X_IN) ;
120
assign o_en = (r_state == P_DONE);
121
 
122
assign w_set_v0_x = (r_state == P_V0_X_IN) & i_en;
123
assign w_set_v0_y = (r_state == P_V0_Y_IN);
124
assign w_set_v1_x = (r_state == P_V1_X_IN) & i_en;
125
assign w_set_v1_y = (r_state == P_V1_Y_IN);
126
assign w_set_v2_x = (r_state == P_V2_X_IN) & i_en;
127
assign w_set_v2_y = (r_state == P_V2_Y_IN);
128
assign w_set_y = w_set_v0_x | w_set_v1_x | w_set_v2_x;
129
assign w_f22_in = (w_set_y) ? i_vx : r_vy;
130
 
131
 
132
// o_outcode[0] : -X plane
133
// o_outcode[1] : +X plane
134
// o_outcode[2] : -Y plane
135
// o_outcode[3] : +Y plane
136
// o_outcode[4] : -Z plane
137
// o_outcode[5] : +Z plane
138 4 specular
assign  w_all_inside = ~(|(r_v0_outcode | r_v1_outcode | r_v2_outcode));
139
assign  w_all_outside = |(r_v0_outcode & r_v1_outcode & r_v2_outcode);
140
//assign  w_all_inside = ~(r_v0_outcode | r_v1_outcode | r_v2_outcode);
141
//assign  w_all_outside = (r_v0_outcode & r_v1_outcode & r_v2_outcode);
142 2 specular
assign  w_z_outside = (|r_v0_outcode[5:4]) |
143
                      (|r_v1_outcode[5:4]) |
144
                      (|r_v2_outcode[5:4]);
145
assign w_tri_outside = w_all_outside | w_z_outside;
146
 
147
//////////////////////////////////
148
// always
149
//////////////////////////////////
150
always @(posedge clk_core) begin
151
  if (w_set_v0_x) r_v0_x <= w_i16[`D3D_FTOI_WIDTH:1];  // divide by 2 sign expansion
152
  if (w_set_v0_y) r_v0_y <= w_i16[`D3D_FTOI_WIDTH:1];
153
  if (w_set_v1_x) r_v1_x <= w_i16[`D3D_FTOI_WIDTH:1];
154
  if (w_set_v1_y) r_v1_y <= w_i16[`D3D_FTOI_WIDTH:1];
155
  if (w_set_v2_x) r_v2_x <= w_i16[`D3D_FTOI_WIDTH:1];
156
  if (w_set_v2_y) r_v2_y <= w_i16[`D3D_FTOI_WIDTH:1];
157
  if (w_set_v0_x) r_v0_outcode <= i_outcode;
158
  if (w_set_v1_x) r_v1_outcode <= i_outcode;
159
  if (w_set_v2_x) r_v2_outcode <= i_outcode;
160
end
161
 
162
always @(posedge clk_core) begin
163
  if (w_set_y) r_vy <= i_vy;
164
end
165
 
166
`ifdef D3D_SYNC_RESET
167
always @(posedge clk_core) begin
168
`else
169
always @(posedge clk_core or negedge rst_x) begin
170
`endif
171
  if (rst_x == `D3D_RESET_POL) begin
172
    r_state <= P_V0_X_IN;
173
  end else begin
174
    case (r_state)
175
      P_V0_X_IN: begin
176
       if (i_en) r_state <= P_V0_Y_IN;
177
      end
178
      P_V0_Y_IN: r_state <= P_V1_X_IN;
179
      P_V1_X_IN: begin
180
        if (i_en) r_state <= P_V1_Y_IN;
181
      end
182
      P_V1_Y_IN: r_state <= P_V2_X_IN;
183
      P_V2_X_IN: begin
184
        if (i_en) r_state <= P_V2_Y_IN;
185
      end
186
      P_V2_Y_IN: begin  // clipping check
187
        if (w_tri_outside) r_state <= P_V0_X_IN;
188
        else r_state <= P_DONE;
189
      end
190
      P_DONE: begin
191
       if (i_ack) r_state <= P_V0_X_IN;
192
      end
193
    endcase
194
  end
195
end
196
 
197
//////////////////////////////////
198
// module instance
199
//////////////////////////////////
200
fm_3d_f22_to_i u_ftoi (
201
  .i_a(w_f22_in),
202
  .o_b(w_i16)
203
);
204
 
205
`ifdef RTL_DEBUG
206
integer tri_no;
207
initial tri_no = 0;
208
 
209
  always @(posedge clk_core) begin
210
    if (o_en & i_ack) begin
211
      $display("triangle No. %d : v0 = %d %d, v1 = %d %d, v2 = %d %d",
212
                  tri_no,o_v0_x,o_v0_y,o_v1_x,o_v1_y,o_v2_x,o_v2_y);
213
      tri_no = tri_no + 1;
214
    end
215
  end
216
`endif
217
endmodule

powered by: WebSVN 2.1.0

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