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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.1/] [rtl/] [GEO/] [Module_TriangleFetch.v] - Blame information for rev 204

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
 
4
`define TFU_AFTER_RESET                                                                 0
5
`define TFU_IDLE                                                                                        1
6
`define TFU_REQUEST_VERTEX                                                              2
7
`define TFU_WAIT_FOR_VERTEX                                                     3
8
`define TFU_REQUEST_NEXT_VERTEX_DIFFUSE                 4
9
`define TFU_REQUEST_DIFFUSE_COLOR                                       5
10
`define TFU_WAIT_FOR_DIFFUSE_COLOR                                      6
11
`define TFU_SET_WBM_INITIAL_ADDRESS                             7
12
`define TFU_CHECK_FOR_WBM_ADDRESS_SET                           8
13
`define TFU_SET_DIFFUSE_COLOR_ADDRESS                           9
14
`define TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE              10
15
`define TFU_INC_WRITE_ADDRESS_DIFFUSE                           11
16
`define TFU_DONE                                                                                        12
17
/**********************************************************************************
18
Theia, Ray Cast Programable graphic Processing Unit.
19
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
20
 
21
This program is free software; you can redistribute it and/or
22
modify it under the terms of the GNU General Public License
23
as published by the Free Software Foundation; either version 2
24
of the License, or (at your option) any later version.
25
 
26
This program is distributed in the hope that it will be useful,
27
but WITHOUT ANY WARRANTY; without even the implied warranty of
28
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
GNU General Public License for more details.
30
 
31
You should have received a copy of the GNU General Public License
32
along with this program; if not, write to the Free Software
33
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
34
 
35
***********************************************************************************/
36
/*
37
 
38
 
39
        Warning: setting iTrigger while oBusy = 1 will reset the Up counters!
40
 
41
*/
42
//-------------------------------------------------------------------------
43
module TriangleFetchUnit
44
(
45
        input wire                                      Clock,
46
        input wire                                      Reset,
47
        input   wire                                    iTrigger,
48
        //output reg                                    oBusy,                                                  //I am currently busy
49
        output reg                                      oDone,                                                  //Done reading trinagle data
50
        //Wires from GFSM
51
        input   wire                                    iDataAvailable,                         //Data is ready
52
        input wire[`WIDTH-1:0]   iInitialAddress,                                //The initial address of the data
53
        input wire                                      iSetAddressOffset,                      //Set the iInitialAddress Now
54
        //Wires from Control Register
55
        input wire                                      iCR_TextureMappingEnabled,      //Is the texture map fearure enable?
56
 
57
        //Wires to WBM
58
        output reg                                                                              oTriggerWBM,
59
        output wire[`WIDTH-1:0]                                          oAddressWBM,
60
        output reg                                                                              oSetAddressWBM,
61
        output wire[`DATA_ADDRESS_WIDTH-1:0]     oRAMWriteAddress,
62
        output reg                                                                              oRAMWriteEnable
63
 
64
);
65
 
66
 
67
 
68
assign oAddressWBM = iInitialAddress;///Must change or will always read first triangle in the list....
69
 
70
 
71
reg [4:0]        CurrentState,NextState;
72
reg IncWriteAddress,IncVertexCount;
73
wire [2:0] wVertexCount;
74
//-----------------------------
75
UpCounter_3 TNF_VC1
76
(
77
.Clock( Clock ),
78
.Reset( iTrigger ),
79
.Initial( 3'b0 ),
80
.Enable( IncVertexCount ),
81
.Q( wVertexCount )
82
);
83
 
84
 
85
//-----------------------------
86
UpCounter_16E TNF_TFU_2
87
(
88
 
89
.Clock( Clock ),
90
.Reset( iTrigger ),
91
.Initial( `CREG_V0 ),//iRAMWriteOffset ),
92
.Enable( IncWriteAddress ),
93
.Q( oRAMWriteAddress )
94
 
95
);
96
 
97
//------------------------------------------------
98
  always @(posedge Clock or posedge Reset)
99
  begin
100
 
101
    if (Reset)
102
                CurrentState <= `TFU_AFTER_RESET;
103
    else
104
                CurrentState <= NextState;
105
 
106
  end
107
 
108
//------------------------------------
109
always @( * )
110
   begin
111
   case (CurrentState)
112
        //------------------------------------
113
        `TFU_AFTER_RESET:
114
        begin
115
 
116
                oTriggerWBM                     <= 0;
117
                oSetAddressWBM          <= 0;
118
                IncWriteAddress         <= 0;
119
                IncVertexCount          <= 0;
120
        //      oBusy                                   <= 0;
121
                oDone                                   <= 0;
122
                oRAMWriteEnable <= 0;
123
 
124
                NextState <= `TFU_IDLE;
125
   end
126
        //------------------------------------
127
        `TFU_IDLE:
128
        begin
129
 
130
                oTriggerWBM                     <= 0;
131
                oSetAddressWBM          <= 0;
132
                IncWriteAddress         <= 0;
133
                IncVertexCount          <= 0;
134
        //      oBusy                                   <= 0;
135
                oDone                                   <= 0;
136
                oRAMWriteEnable <= 0;
137
 
138
                if ( iTrigger )
139
                        NextState <= `TFU_CHECK_FOR_WBM_ADDRESS_SET;
140
                else
141
                        NextState <= `TFU_IDLE;
142
 
143
        end
144
        //------------------------------------
145
        `TFU_CHECK_FOR_WBM_ADDRESS_SET:
146
        begin
147
                oTriggerWBM                     <= 0;
148
                oSetAddressWBM          <= 0;
149
                IncWriteAddress         <= 0;
150
                IncVertexCount          <= 0;
151
        //      oBusy                                   <= 0;
152
                oDone                                   <= 0;
153
                oRAMWriteEnable <= 0;
154
 
155
                if ( iSetAddressOffset )
156
                        NextState <= `TFU_SET_WBM_INITIAL_ADDRESS;
157
                else
158
                        NextState <= `TFU_REQUEST_VERTEX;
159
 
160
        end
161
        //------------------------------------
162
        `TFU_SET_WBM_INITIAL_ADDRESS:
163
        begin
164
 
165
                `ifdef DEBUG
166
                        $display("TFU: TFU_SET_WBM_INITIAL_ADDRESS");
167
                `endif
168
 
169
                oTriggerWBM                     <= 0;
170
                oSetAddressWBM          <= 1; //*
171
                IncWriteAddress         <= 0;
172
                IncVertexCount          <= 0;
173
        //      oBusy                                   <= 1; //*
174
                oDone                                   <= 0;
175
                oRAMWriteEnable <= 0;
176
 
177
                NextState <= `TFU_REQUEST_VERTEX;
178
        end
179
        //------------------------------------
180
        `TFU_REQUEST_VERTEX:
181
        begin
182
                oTriggerWBM                     <= 1; //*
183
                oSetAddressWBM          <= 0;
184
                IncWriteAddress         <= 0;
185
                IncVertexCount          <= 1; //*
186
        //      oBusy                                   <= 1; 
187
                oDone                                   <= 0;
188
                oRAMWriteEnable <= 1; //*
189
                //$display("TFU_REQUEST_VERTEX %d to wirte to %d\n",oAddressWBM,oRAMWriteAddress);
190
                NextState <= `TFU_WAIT_FOR_VERTEX;
191
        end
192
        //------------------------------------
193
        `TFU_WAIT_FOR_VERTEX:
194
        begin
195
 
196
                oTriggerWBM                     <= 1;
197
                oSetAddressWBM          <= 0;
198
                IncWriteAddress         <= 0;
199
                IncVertexCount          <= 0;
200
        //      oBusy                                   <= 1; //*
201
                oDone                                   <= 0;
202
                oRAMWriteEnable <= 1;
203
 
204
 
205
                if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b0)
206
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_DIFFUSE;
207
                else if ( iDataAvailable &&     iCR_TextureMappingEnabled == 1'b1)
208
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE;
209
                else
210
                        NextState <= `TFU_WAIT_FOR_VERTEX;
211
        end
212
        //------------------------------------
213
        `TFU_REQUEST_NEXT_VERTEX_DIFFUSE:
214
        begin
215
                oTriggerWBM                     <= 0;
216
                oSetAddressWBM          <= 0;
217
                IncWriteAddress         <= 1; //*
218
                IncVertexCount          <= 0;
219
        //      oBusy                                   <= 1; 
220
                oDone                                   <= 0;
221
                oRAMWriteEnable <= 0;
222
 
223
 
224
                //if ( wVertexCount == 3)
225
                //      NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
226
                //else
227
                        NextState <= `TFU_INC_WRITE_ADDRESS_DIFFUSE;
228
        end
229
        //------------------------------------
230
        `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE:
231
        begin
232
                oTriggerWBM                     <= 0;
233
                oSetAddressWBM          <= 0;
234
                IncWriteAddress         <= 1; //*
235
                IncVertexCount          <= 0;
236
        //      oBusy                                   <= 1; 
237
                oDone                                   <= 0;
238
                oRAMWriteEnable <= 0;
239
 
240
                //$display("TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE, count = %d",wVertexCount);
241
                if ( wVertexCount == 6)
242
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
243
                else
244
                        NextState <= `TFU_REQUEST_VERTEX;
245
        end
246
        //------------------------------------
247
        `TFU_INC_WRITE_ADDRESS_DIFFUSE:
248
        begin
249
                oTriggerWBM                     <= 0;
250
                oSetAddressWBM          <= 0;
251
                IncWriteAddress         <= 1; //*
252
                IncVertexCount          <= 0;
253
        //      oBusy                                   <= 1; 
254
                oDone                                   <= 0;
255
                oRAMWriteEnable <= 0;
256
 
257
        //      $display(":) TFU_REQUEST_NEXT_VERTEX_DIFFUSE, count = %d",wVertexCount);
258
                if ( wVertexCount == 3)
259
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
260
                else
261
                        NextState <= `TFU_REQUEST_VERTEX;
262
        end
263
        //------------------------------------
264
        `TFU_REQUEST_DIFFUSE_COLOR:
265
        begin
266
 
267
//              $display("TFU_REQUEST_DIFFUSE_COLOR: Writting to %d",oRAMWriteAddress);
268
                oTriggerWBM                     <= 1;
269
                oSetAddressWBM          <= 0;
270
                IncWriteAddress         <= 0;
271
                IncVertexCount          <= 0;
272
        //      oBusy                                   <= 1; 
273
                oDone                                   <= 0;
274
                oRAMWriteEnable <= 1;
275
 
276
                NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
277
 
278
        end
279
        //------------------------------------
280
        `TFU_WAIT_FOR_DIFFUSE_COLOR:
281
        begin
282
                oTriggerWBM                     <= 1;
283
                oSetAddressWBM          <= 0;
284
                IncWriteAddress         <= 0;
285
                IncVertexCount          <= 0;
286
        //      oBusy                                   <= 1; 
287
                oDone                                   <= 0; //*
288
                oRAMWriteEnable <= 1;
289
 
290
                if ( iDataAvailable )
291
                        NextState <= `TFU_DONE;
292
                else
293
                        NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
294
 
295
        end
296
 
297
        //------------------------------------
298
        `TFU_DONE:
299
        begin
300
                oTriggerWBM                     <= 0;
301
                oSetAddressWBM          <= 0;
302
                IncWriteAddress         <= 0;
303
                IncVertexCount          <= 0;
304
        //      oBusy                                   <= 0;   //*
305
                oDone                                   <= 1; //*
306
                oRAMWriteEnable <= 0;
307
 
308
                NextState <= `TFU_IDLE;
309
        end
310
        //------------------------------------
311
        default:
312
        begin
313
                oTriggerWBM                     <= 0;
314
                oSetAddressWBM          <= 0;
315
                IncWriteAddress         <= 0;
316
                IncVertexCount          <= 0;
317
        //      oBusy                                   <= 0;
318
                oDone                                   <= 0;
319
                oRAMWriteEnable <= 0;
320
 
321
                NextState <= `TFU_IDLE;
322
        end
323
        //------------------------------------
324
        endcase
325
 
326
end //always
327
endmodule
328
//-------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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