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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_geo_tri.v] - Blame information for rev 2

Go to most recent revision | 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
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
14
//
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
 
43
`include "fm_3d_define.v"
44
module fm_geo_tri (
45
  input         clk_core,
46
  input         rst_x,
47
  output        o_state,
48
  // vertex input
49
  input         i_en,
50
  output        o_ack,
51
  input  [5:0]  i_outcode,
52
  input  [21:0] i_vx,
53
  input  [21:0] i_vy,
54
  // vertex output
55
  output        o_en,
56
  input         i_ack,
57
  output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
58
  output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
59
  output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
60
  output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
61
  output [`D3D_FTOI_WIDTH-1:0] o_v2_x,
62
  output [`D3D_FTOI_WIDTH-1:0] o_v2_y
63
);
64
localparam P_V0_X_IN = 'd0;
65
localparam P_V0_Y_IN = 'd1;
66
localparam P_V1_X_IN = 'd2;
67
localparam P_V1_Y_IN = 'd3;
68
localparam P_V2_X_IN = 'd4;
69
localparam P_V2_Y_IN = 'd5;
70
localparam P_DONE    = 'd6;
71
 
72
//////////////////////////////////
73
// regs 
74
//////////////////////////////////
75
reg [2:0]      r_state;
76
reg [21:0]     r_vy;
77
reg [`D3D_FTOI_WIDTH-1:0]     r_v0_x;
78
reg [`D3D_FTOI_WIDTH-1:0]     r_v0_y;
79
reg [`D3D_FTOI_WIDTH-1:0]     r_v1_x;
80
reg [`D3D_FTOI_WIDTH-1:0]     r_v1_y;
81
reg [`D3D_FTOI_WIDTH-1:0]     r_v2_x;
82
reg [`D3D_FTOI_WIDTH-1:0]     r_v2_y;
83
reg [5:0]      r_v0_outcode;
84
reg [5:0]      r_v1_outcode;
85
reg [5:0]      r_v2_outcode;
86
//////////////////////////////////
87
// wire
88
//////////////////////////////////
89
wire [21:0] w_f22_in;
90
wire [15:0] w_i16;
91
 
92
wire        w_set_v0_x;
93
wire        w_set_v0_y;
94
wire        w_set_v1_x;
95
wire        w_set_v1_y;
96
wire        w_set_v2_x;
97
wire        w_set_v2_y;
98
wire        w_set_y;
99
wire        w_all_inside;
100
wire        w_all_outside;
101
wire        w_z_outside;
102
wire        w_tri_outside;
103
 
104
//////////////////////////////////
105
// assign
106
//////////////////////////////////
107
assign o_state = (r_state == P_V0_X_IN);
108
assign o_v0_x = r_v0_x;
109
assign o_v0_y = r_v0_y;
110
assign o_v1_x = r_v1_x;
111
assign o_v1_y = r_v1_y;
112
assign o_v2_x = r_v2_x;
113
assign o_v2_y = r_v2_y;
114
assign o_ack = (r_state == P_V0_X_IN) |
115
              (r_state == P_V1_X_IN) |
116
              (r_state == P_V2_X_IN) ;
117
assign o_en = (r_state == P_DONE);
118
 
119
assign w_set_v0_x = (r_state == P_V0_X_IN) & i_en;
120
assign w_set_v0_y = (r_state == P_V0_Y_IN);
121
assign w_set_v1_x = (r_state == P_V1_X_IN) & i_en;
122
assign w_set_v1_y = (r_state == P_V1_Y_IN);
123
assign w_set_v2_x = (r_state == P_V2_X_IN) & i_en;
124
assign w_set_v2_y = (r_state == P_V2_Y_IN);
125
assign w_set_y = w_set_v0_x | w_set_v1_x | w_set_v2_x;
126
assign w_f22_in = (w_set_y) ? i_vx : r_vy;
127
 
128
 
129
// o_outcode[0] : -X plane
130
// o_outcode[1] : +X plane
131
// o_outcode[2] : -Y plane
132
// o_outcode[3] : +Y plane
133
// o_outcode[4] : -Z plane
134
// o_outcode[5] : +Z plane
135
 
136
assign  w_all_inside = ~(r_v0_outcode | r_v1_outcode | r_v2_outcode);
137
assign  w_all_outside = (r_v0_outcode & r_v1_outcode & r_v2_outcode);
138
assign  w_z_outside = (|r_v0_outcode[5:4]) |
139
                      (|r_v1_outcode[5:4]) |
140
                      (|r_v2_outcode[5:4]);
141
assign w_tri_outside = w_all_outside | w_z_outside;
142
 
143
//////////////////////////////////
144
// always
145
//////////////////////////////////
146
always @(posedge clk_core) begin
147
  if (w_set_v0_x) r_v0_x <= w_i16[`D3D_FTOI_WIDTH:1];  // divide by 2 sign expansion
148
  if (w_set_v0_y) r_v0_y <= w_i16[`D3D_FTOI_WIDTH:1];
149
  if (w_set_v1_x) r_v1_x <= w_i16[`D3D_FTOI_WIDTH:1];
150
  if (w_set_v1_y) r_v1_y <= w_i16[`D3D_FTOI_WIDTH:1];
151
  if (w_set_v2_x) r_v2_x <= w_i16[`D3D_FTOI_WIDTH:1];
152
  if (w_set_v2_y) r_v2_y <= w_i16[`D3D_FTOI_WIDTH:1];
153
  if (w_set_v0_x) r_v0_outcode <= i_outcode;
154
  if (w_set_v1_x) r_v1_outcode <= i_outcode;
155
  if (w_set_v2_x) r_v2_outcode <= i_outcode;
156
end
157
 
158
always @(posedge clk_core) begin
159
  if (w_set_y) r_vy <= i_vy;
160
end
161
 
162
`ifdef D3D_SYNC_RESET
163
always @(posedge clk_core) begin
164
`else
165
always @(posedge clk_core or negedge rst_x) begin
166
`endif
167
  if (rst_x == `D3D_RESET_POL) begin
168
    r_state <= P_V0_X_IN;
169
  end else begin
170
    case (r_state)
171
      P_V0_X_IN: begin
172
       if (i_en) r_state <= P_V0_Y_IN;
173
      end
174
      P_V0_Y_IN: r_state <= P_V1_X_IN;
175
      P_V1_X_IN: begin
176
        if (i_en) r_state <= P_V1_Y_IN;
177
      end
178
      P_V1_Y_IN: r_state <= P_V2_X_IN;
179
      P_V2_X_IN: begin
180
        if (i_en) r_state <= P_V2_Y_IN;
181
      end
182
      P_V2_Y_IN: begin  // clipping check
183
        if (w_tri_outside) r_state <= P_V0_X_IN;
184
        else r_state <= P_DONE;
185
      end
186
      P_DONE: begin
187
       if (i_ack) r_state <= P_V0_X_IN;
188
      end
189
    endcase
190
  end
191
end
192
 
193
//////////////////////////////////
194
// module instance
195
//////////////////////////////////
196
fm_3d_f22_to_i u_ftoi (
197
  .i_a(w_f22_in),
198
  .o_b(w_i16)
199
);
200
 
201
`ifdef RTL_DEBUG
202
integer tri_no;
203
initial tri_no = 0;
204
 
205
  always @(posedge clk_core) begin
206
    if (o_en & i_ack) begin
207
      $display("triangle No. %d : v0 = %d %d, v1 = %d %d, v2 = %d %d",
208
                  tri_no,o_v0_x,o_v0_y,o_v1_x,o_v1_y,o_v2_x,o_v2_y);
209
      tri_no = tri_no + 1;
210
    end
211
  end
212
`endif
213
endmodule

powered by: WebSVN 2.1.0

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