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

Subversion Repositories theia_gpu

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

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 82 diegovalve
        output wire[`DATA_ADDRESS_WIDTH-1:0]     oRAMWriteAddress,
62
        `ifdef DEBUG
63
        input wire[`MAX_CORES-1:0]            iDebug_CoreID,
64
        `endif
65 28 diegovalve
        output reg                                                                              oRAMWriteEnable
66
 
67
);
68
 
69
 
70
 
71
assign oAddressWBM = iInitialAddress;///Must change or will always read first triangle in the list....
72
 
73
 
74
reg [4:0]        CurrentState,NextState;
75
reg IncWriteAddress,IncVertexCount;
76
wire [2:0] wVertexCount;
77
//-----------------------------
78
UpCounter_3 TNF_VC1
79
(
80
.Clock( Clock ),
81
.Reset( iTrigger ),
82
.Initial( 3'b0 ),
83
.Enable( IncVertexCount ),
84
.Q( wVertexCount )
85
);
86
 
87
 
88
//-----------------------------
89
UpCounter_16E TNF_TFU_2
90
(
91
 
92
.Clock( Clock ),
93
.Reset( iTrigger ),
94
.Initial( `CREG_V0 ),//iRAMWriteOffset ),
95
.Enable( IncWriteAddress ),
96
.Q( oRAMWriteAddress )
97
 
98
);
99
 
100
//------------------------------------------------
101
  always @(posedge Clock or posedge Reset)
102
  begin
103
 
104
    if (Reset)
105
                CurrentState <= `TFU_AFTER_RESET;
106
    else
107
                CurrentState <= NextState;
108
 
109
  end
110
 
111
//------------------------------------
112
always @( * )
113
   begin
114
   case (CurrentState)
115
        //------------------------------------
116
        `TFU_AFTER_RESET:
117
        begin
118
 
119
                oTriggerWBM                     <= 0;
120
                oSetAddressWBM          <= 0;
121
                IncWriteAddress         <= 0;
122
                IncVertexCount          <= 0;
123
        //      oBusy                                   <= 0;
124
                oDone                                   <= 0;
125
                oRAMWriteEnable <= 0;
126
 
127
                NextState <= `TFU_IDLE;
128
   end
129
        //------------------------------------
130
        `TFU_IDLE:
131
        begin
132
 
133
                oTriggerWBM                     <= 0;
134
                oSetAddressWBM          <= 0;
135
                IncWriteAddress         <= 0;
136
                IncVertexCount          <= 0;
137
        //      oBusy                                   <= 0;
138
                oDone                                   <= 0;
139
                oRAMWriteEnable <= 0;
140
 
141
                if ( iTrigger )
142
                        NextState <= `TFU_CHECK_FOR_WBM_ADDRESS_SET;
143
                else
144
                        NextState <= `TFU_IDLE;
145
 
146
        end
147
        //------------------------------------
148
        `TFU_CHECK_FOR_WBM_ADDRESS_SET:
149
        begin
150
                oTriggerWBM                     <= 0;
151
                oSetAddressWBM          <= 0;
152
                IncWriteAddress         <= 0;
153
                IncVertexCount          <= 0;
154
        //      oBusy                                   <= 0;
155
                oDone                                   <= 0;
156
                oRAMWriteEnable <= 0;
157
 
158
                if ( iSetAddressOffset )
159
                        NextState <= `TFU_SET_WBM_INITIAL_ADDRESS;
160
                else
161
                        NextState <= `TFU_REQUEST_VERTEX;
162
 
163
        end
164
        //------------------------------------
165
        `TFU_SET_WBM_INITIAL_ADDRESS:
166
        begin
167
 
168
                `ifdef DEBUG
169
                        $display("TFU: TFU_SET_WBM_INITIAL_ADDRESS");
170
                `endif
171
 
172
                oTriggerWBM                     <= 0;
173
                oSetAddressWBM          <= 1; //*
174
                IncWriteAddress         <= 0;
175
                IncVertexCount          <= 0;
176
        //      oBusy                                   <= 1; //*
177
                oDone                                   <= 0;
178
                oRAMWriteEnable <= 0;
179
 
180
                NextState <= `TFU_REQUEST_VERTEX;
181
        end
182
        //------------------------------------
183
        `TFU_REQUEST_VERTEX:
184
        begin
185
                oTriggerWBM                     <= 1; //*
186
                oSetAddressWBM          <= 0;
187
                IncWriteAddress         <= 0;
188
                IncVertexCount          <= 1; //*
189
        //      oBusy                                   <= 1; 
190
                oDone                                   <= 0;
191
                oRAMWriteEnable <= 1; //*
192
                //$display("TFU_REQUEST_VERTEX %d to wirte to %d\n",oAddressWBM,oRAMWriteAddress);
193
                NextState <= `TFU_WAIT_FOR_VERTEX;
194
        end
195
        //------------------------------------
196
        `TFU_WAIT_FOR_VERTEX:
197
        begin
198
 
199
                oTriggerWBM                     <= 1;
200
                oSetAddressWBM          <= 0;
201
                IncWriteAddress         <= 0;
202
                IncVertexCount          <= 0;
203
        //      oBusy                                   <= 1; //*
204
                oDone                                   <= 0;
205
                oRAMWriteEnable <= 1;
206
 
207
 
208
                if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b0)
209
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_DIFFUSE;
210
                else if ( iDataAvailable &&     iCR_TextureMappingEnabled == 1'b1)
211
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE;
212
                else
213
                        NextState <= `TFU_WAIT_FOR_VERTEX;
214
        end
215
        //------------------------------------
216
        `TFU_REQUEST_NEXT_VERTEX_DIFFUSE:
217
        begin
218
                oTriggerWBM                     <= 0;
219
                oSetAddressWBM          <= 0;
220
                IncWriteAddress         <= 1; //*
221
                IncVertexCount          <= 0;
222
        //      oBusy                                   <= 1; 
223
                oDone                                   <= 0;
224
                oRAMWriteEnable <= 0;
225
 
226
 
227
                //if ( wVertexCount == 3)
228
                //      NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
229
                //else
230
                        NextState <= `TFU_INC_WRITE_ADDRESS_DIFFUSE;
231
        end
232
        //------------------------------------
233
        `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE:
234
        begin
235
                oTriggerWBM                     <= 0;
236
                oSetAddressWBM          <= 0;
237
                IncWriteAddress         <= 1; //*
238
                IncVertexCount          <= 0;
239
        //      oBusy                                   <= 1; 
240
                oDone                                   <= 0;
241
                oRAMWriteEnable <= 0;
242
 
243
                //$display("TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE, count = %d",wVertexCount);
244
                if ( wVertexCount == 6)
245
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
246
                else
247
                        NextState <= `TFU_REQUEST_VERTEX;
248
        end
249
        //------------------------------------
250
        `TFU_INC_WRITE_ADDRESS_DIFFUSE:
251
        begin
252
                oTriggerWBM                     <= 0;
253
                oSetAddressWBM          <= 0;
254
                IncWriteAddress         <= 1; //*
255
                IncVertexCount          <= 0;
256
        //      oBusy                                   <= 1; 
257
                oDone                                   <= 0;
258
                oRAMWriteEnable <= 0;
259
 
260
        //      $display(":) TFU_REQUEST_NEXT_VERTEX_DIFFUSE, count = %d",wVertexCount);
261
                if ( wVertexCount == 3)
262
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
263
                else
264
                        NextState <= `TFU_REQUEST_VERTEX;
265
        end
266
        //------------------------------------
267
        `TFU_REQUEST_DIFFUSE_COLOR:
268
        begin
269
 
270
//              $display("TFU_REQUEST_DIFFUSE_COLOR: Writting to %d",oRAMWriteAddress);
271
                oTriggerWBM                     <= 1;
272
                oSetAddressWBM          <= 0;
273
                IncWriteAddress         <= 0;
274
                IncVertexCount          <= 0;
275
        //      oBusy                                   <= 1; 
276
                oDone                                   <= 0;
277
                oRAMWriteEnable <= 1;
278
 
279
                NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
280
 
281
        end
282
        //------------------------------------
283
        `TFU_WAIT_FOR_DIFFUSE_COLOR:
284
        begin
285
                oTriggerWBM                     <= 1;
286
                oSetAddressWBM          <= 0;
287
                IncWriteAddress         <= 0;
288
                IncVertexCount          <= 0;
289
        //      oBusy                                   <= 1; 
290
                oDone                                   <= 0; //*
291
                oRAMWriteEnable <= 1;
292
 
293
                if ( iDataAvailable )
294
                        NextState <= `TFU_DONE;
295
                else
296
                        NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
297
 
298
        end
299
 
300
        //------------------------------------
301
        `TFU_DONE:
302
        begin
303
                oTriggerWBM                     <= 0;
304
                oSetAddressWBM          <= 0;
305
                IncWriteAddress         <= 0;
306
                IncVertexCount          <= 0;
307
        //      oBusy                                   <= 0;   //*
308
                oDone                                   <= 1; //*
309
                oRAMWriteEnable <= 0;
310
 
311
                NextState <= `TFU_IDLE;
312
        end
313
        //------------------------------------
314
        default:
315
        begin
316
                oTriggerWBM                     <= 0;
317
                oSetAddressWBM          <= 0;
318
                IncWriteAddress         <= 0;
319
                IncVertexCount          <= 0;
320
        //      oBusy                                   <= 0;
321
                oDone                                   <= 0;
322
                oRAMWriteEnable <= 0;
323
 
324
                NextState <= `TFU_IDLE;
325
        end
326
        //------------------------------------
327
        endcase
328
 
329
end //always
330
endmodule
331
//-------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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