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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [tags/] [latest_stable/] [rtl/] [GPU/] [HOST/] [Module_Host.v] - Blame information for rev 150

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 124 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
 
4
 
5
 
6
/**********************************************************************************
7
Theia, Ray Cast Programable graphic Processing Unit.
8
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
9
 
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
14
 
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
GNU General Public License for more details.
19
 
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23
 
24
***********************************************************************************/
25
 
26
 
27
/*******************************************************************************
28
Module Description:
29
 
30
WIP
31
 
32
*******************************************************************************/
33
 
34
 
35
 
36 143 diegovalve
`define MAX_VERTEX_IN_FRAME      `WIDTH'd7 // WAS 8'd6
37 124 diegovalve
`define TAG_INSTRUCTION_ADDRESS_TYPE 2'b01
38
`define TAG_DATA_ADDRESS_TYPE        2'b10
39
`define SELECT_INST_MEM              3'b00
40
`define SELECT_SCENE_MEM             3'b01
41
`define SELECT_GEO_MEM               3'b10
42
 
43 143 diegovalve
 
44 124 diegovalve
`define HOST_IDLE                       0
45
`define HOST_WRITE_INSTRUCTION          1
46
`define HOST_WAIT_INSTRUCTION           2
47
`define HOST_WRITE_SCENE_PARAMS         3
48
`define HOST_WAIT_SCENE_PARAMS          4
49
`define HOST_PREPARE_CORE_CONFIG        5
50
`define HOST_UNICAST_CORE_CONFIG        6
51
`define HOST_WAIT_CORE_CONFIG           7
52
`define HOST_PREPARE_NEXT_CORE_CONFIG   8
53
`define HOST_WAIT_DATA_READ_CONFIRMATION       10
54
`define HOST_BROADCAST_NEXT_VERTEX   11
55
`define HOST_WAIT_FOR_VERTEX    12
56
`define HOST_INITIAL_SCENE_PARAMS_STAGE 13
57
`define HOST_PREPARE_FOR_GEO_REQUESTS   14
58
`define HOST_ACK_GEO_REQUEST            15
59
`define HOST_GET_PRIMITIVE_COUNT    16
60
`define HOST_LAST_PRIMITIVE_REACHED 17
61
`define HOST_GPU_EXECUTION_DONE 18
62
 
63
//---------------------------------------------------------------
64
module Module_Host
65
(
66
        input wire Clock,
67
        input wire Reset,
68
        input wire iEnable,
69
        input wire iHostDataReadConfirmed,
70
        input wire [`WB_WIDTH-1:0] iMemorySize,
71
        input wire [`WB_WIDTH-1:0] iPrimitiveCount,
72
 
73
        //To Memory
74
        output wire [`WB_WIDTH-1:0] oReadAddress,
75
        input wire [`WB_WIDTH-1:0]  iReadData,
76
        input wire iGPUCommitedResults,
77
 
78
        //To Hub/Switch
79
        output wire [`MAX_CORES-1:0]     oCoreSelectMask,
80
        output reg [2:0]                 oMemSelect,
81
        output wire [`WB_WIDTH-1:0]      DAT_O,
82
        output wire [`WB_WIDTH-1:0]      ADR_O,
83
        output reg[1:0]                  TGA_O,
84
        output reg[`MAX_CORES-1:0]       RENDREN_O,
85
        output wire                      CYC_O,
86
        output wire                      STB_O,
87
        output reg                       MST_O,
88
        output wire                      WE_O,
89
        input  wire                                                     GRDY_I, //This means all the cores are done rading the primitive we send
90
   output reg                       GACK_O,     //We set this to ACK that the cored read the primitive
91
        output wire                       STDONE_O,
92
        output reg                       oHostDataAvailable,
93
        input wire                       iGPUDone,
94 143 diegovalve
        `ifndef NO_DISPLAY_STATS
95
        input wire [`WIDTH-1:0] iDebugWidth,
96
        `endif
97 124 diegovalve
        input wire                       ACK_I
98
);
99
//---------------------------------------------------------------
100
wire wLastPrimitive;
101
assign wLastPrimitive = (wVertexCount >= iPrimitiveCount) ? 1'b1 : 1'b0;
102
assign STDONE_O = wLastPrimitive;
103
 
104
wire  wWBMDone;
105
reg rWBMEnable,rWBMReset,rCoreBroadCast;
106
reg [`WB_WIDTH-1:0] rInitiaReadAddr;
107
wire [`MAX_CORES-1:0] wCoreSelect;
108
wire wLastValidReadAddress;
109
wire [`WB_WIDTH-1:0] wWriteAddress;
110 143 diegovalve
wire [`WIDTH-1:0] wVertexCount;
111 124 diegovalve
reg [`WB_WIDTH-1:0] rInitialWriteAddress;
112
reg rSetWriteAddr;
113
reg rIncCoreSelect,rResetVertexCount;
114
//--------------------------------------------------------
115
 
116
assign WE_O = MST_O;
117
 
118
assign oCoreSelectMask =
119
        (rCoreBroadCast) ? `SELECT_ALL_CORES : wCoreSelect;
120
 
121
assign wLastValidReadAddress =
122
        (oReadAddress >= iMemorySize) ? 1'b1 : 1'b0;
123
 
124
wire wLastParameter;
125
assign wLastParameter = (oReadAddress >= 32'h12) ? 1'b1 : 1'b0;
126
//--------------------------------------------------------
127
UPCOUNTER_POSEDGE # (`WB_WIDTH ) UPWADDR
128
        (
129
        .Clock(  Clock                   ),
130
        .Reset(   Reset | rSetWriteAddr  ),
131
        .Enable(  iEnable & wWBMDone     ),
132
        .Initial( rInitialWriteAddress   ),
133
        .Q(       wWriteAddress          )
134
        );
135
 
136
 
137 143 diegovalve
UPCOUNTER_POSEDGE # ( 32 ) PRIMCOUNT
138 124 diegovalve
        (
139
        .Clock(  Clock                   ),
140
        .Reset(   Reset | rResetVertexCount  ),
141
        .Enable(  iEnable & wWBMDone     ),
142 143 diegovalve
        .Initial( `WIDTH'b1   ),
143 124 diegovalve
        .Q(       wVertexCount          )
144
        );
145
//--------------------------------------------------------
146
CIRCULAR_SHIFTLEFT_POSEDGE_EX # (`MAX_CORES ) SHF1
147
(
148
        .Clock(    Clock             ),
149
        .Reset(    Reset             ),
150
        .Initial( `MAX_CORES'b1      ),
151
        .Enable(   rIncCoreSelect    ),
152
        .O(        wCoreSelect       )
153
);
154
//--------------------------------------------------------
155
wire wShortCycle;
156
//For instruction we send 2 packets per cycle
157
//for the other we send 3 packets per cycle
158
assign wShortCycle = (oMemSelect == `SELECT_INST_MEM) ? 1'b1 : 1'b0;
159
 
160
WBMaster WBM
161
(
162
.Clock(            Clock             ),
163
.Reset(            Reset | rWBMReset ),
164
.iEnable(          rWBMEnable        ),
165
.iInitialReadAddr( rInitiaReadAddr   ),
166
.iWriteAddr(       wWriteAddress     ),
167
.oReadAddress(     oReadAddress      ),
168
.iReadData(        iReadData         ),
169
.iShortFlow(        wShortCycle     ),
170
 
171
 
172
.STB_O( STB_O ),
173
.ACK_I( ACK_I ),
174
.CYC_O( CYC_O ),
175
.DAT_O( DAT_O ),
176
.ADR_O( ADR_O ),
177
.oDone( wWBMDone )
178
);
179
 
180
//--------------------------------------------------------
181
// Current State Logic //
182
reg [7:0]                        rHostCurrentState,rHostNextState;
183
always @(posedge Clock or posedge Reset)
184
begin
185
     if( Reset!=1 )
186
        rHostCurrentState <= rHostNextState;
187
          else
188
                  rHostCurrentState <= `HOST_IDLE;
189
end
190
//--------------------------------------------------------
191
 
192 143 diegovalve
reg [63:0] i;
193
reg [63:0] RenderedPixels;
194 124 diegovalve
wire wLastVertexInFrame;
195
assign wLastVertexInFrame =
196
(wVertexCount % `MAX_VERTEX_IN_FRAME == 1'b0 ) ? 1'b1 : 1'b0;
197
 
198
// WAS ((wVertexCount % `MAX_VERTEX_IN_FRAME) == 1'b0 && wVertexCount != 0) ? 1'b1 : 1'b0;
199
 
200
reg [31:0] StartTime;
201
 
202
// Host Finite State Machine //
203
always @( * )
204
        begin
205
 
206
                case (rHostCurrentState)
207
                //----------------------------------------
208
                //Wait for reset sequence to complete,
209
                //Or until we are enabled
210
                `HOST_IDLE:
211
                begin
212 143 diegovalve
                RenderedPixels <= 0;
213
 
214 124 diegovalve
                        rWBMEnable            <= 0;
215
                   rInitiaReadAddr       <= 1;  //Start reading from 1, because 0 is the size
216
                        rWBMReset             <= 0;
217
                        oMemSelect            <= 0;
218
                        TGA_O                 <= 0;
219
                        MST_O                   <= 0;
220
                        rInitialWriteAddress  <= 0;
221
         rSetWriteAddr         <= 0;
222
                        rCoreBroadCast        <= 0;
223
                        rIncCoreSelect        <= 0;
224
                        RENDREN_O                                <= 0;
225
                        rResetVertexCount  <= 0;
226
                        GACK_O                                   <= 0;
227
                        //STDONE_O                                       <= 0;
228
                        oHostDataAvailable    <= 0;
229
 
230
                        if ( ~Reset & iEnable )
231
                                rHostNextState <= `HOST_WRITE_INSTRUCTION;
232
                        else
233
                                rHostNextState <= `HOST_IDLE;
234
                end
235
                //----------------------------------------
236
                //Broadcast the instructions to all the cores
237
                `HOST_WRITE_INSTRUCTION:
238
                begin
239
 
240
                        StartTime <= $time;
241
 
242
                        rWBMEnable            <= 1;                                                                             //Enable Wish bone master
243
                   rInitiaReadAddr       <= 1;                                                                          //Start reading from 1, because 0 is the size
244
                        rWBMReset             <= 0;                                                                              //No need to reset since we just came from reset
245
                        oMemSelect            <= `SELECT_INST_MEM;                                      //Start by sending the instructions
246
                        TGA_O                 <= `TAG_INSTRUCTION_ADDRESS_TYPE;
247
                        MST_O                   <= 1;
248
                        rInitialWriteAddress  <= 0;
249
         rSetWriteAddr         <= 0;
250
                        rCoreBroadCast        <= 1;
251
                        rIncCoreSelect        <= 0;
252
                        RENDREN_O                                <= 0;
253
                        rResetVertexCount  <= 0;
254
                        GACK_O                                   <= 0;
255
                        //STDONE_O                                       <= 0;
256
                        oHostDataAvailable    <= 0;
257
 
258
                        rHostNextState <= `HOST_WAIT_INSTRUCTION;
259
                end
260
                //----------------------------------------
261
                `HOST_WAIT_INSTRUCTION:
262
                begin
263
                        rWBMEnable            <= ~wWBMDone;
264
                   rInitiaReadAddr       <= 0;
265
                        rWBMReset             <= 0;
266
                        oMemSelect            <= `SELECT_INST_MEM;
267
                        TGA_O                 <= `TAG_INSTRUCTION_ADDRESS_TYPE;
268
                        MST_O                   <= 1;
269
                        rInitialWriteAddress  <= 0;
270
         rSetWriteAddr         <= 0;
271
                        rCoreBroadCast        <= 1;
272
                        rIncCoreSelect        <= 0;
273
                        RENDREN_O                                <= 0;
274
                        rResetVertexCount  <= 0;
275
                        GACK_O                                   <= 0;
276
                        //STDONE_O                                       <= 0;
277
                        oHostDataAvailable    <= 0;
278
 
279
                        if ( wWBMDone && ~wLastValidReadAddress )
280
                                rHostNextState <= `HOST_WRITE_INSTRUCTION;
281
                        else if (wWBMDone && wLastValidReadAddress )
282
                                rHostNextState <= `HOST_INITIAL_SCENE_PARAMS_STAGE;
283
                        else
284
                                rHostNextState <= `HOST_WAIT_INSTRUCTION;
285
                end
286
                //----------------------------------------
287
                /*
288
                        Make sure to read-pointer points to the
289
                        first memory address at te params memory
290
                */
291
                `HOST_INITIAL_SCENE_PARAMS_STAGE:
292
                begin
293
                        rWBMEnable            <= 0;
294
                   rInitiaReadAddr       <= 1;                                                                                  //Start reading from 1, because 0 is the size
295
                        rWBMReset             <= 1;
296
                        oMemSelect            <= `SELECT_SCENE_MEM;                                             //We are reading from the scene memory
297
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;                                //We will write to the DATA section of the core MEM
298
                        MST_O                   <= 1;                                                                                   //Keep master signal in 1 for now
299
                        rInitialWriteAddress  <= 0;                                                                                      //We start writing from address zero now
300
         rSetWriteAddr         <= 1;
301
                        rCoreBroadCast        <= 1;                                                                                     //Set to zero to unicast, starting from core 0
302
                        rIncCoreSelect        <= 0;                                                                                      //Set to unicast to the next core
303
                        RENDREN_O                                <= 0;
304
                        rResetVertexCount  <= 0;
305
                        GACK_O                                   <= 0;
306
                        //STDONE_O                                       <= 0;
307
                        oHostDataAvailable    <= 0;
308
 
309
                        rHostNextState <= `HOST_WRITE_SCENE_PARAMS;
310
                end
311
 
312
                //----------------------------------------
313
                //Broadcast the instructions to all the cores
314
                `HOST_WRITE_SCENE_PARAMS:
315
                begin
316
                        rWBMEnable            <= 1;
317
                   rInitiaReadAddr       <= 0;
318
                        rWBMReset             <= 0;
319
                        oMemSelect            <= `SELECT_SCENE_MEM;
320
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
321
                        MST_O                   <= 1;
322
                        rInitialWriteAddress  <= 0;
323
         rSetWriteAddr         <= 0;
324
                        rCoreBroadCast        <= 1;
325
                        rIncCoreSelect        <= 0;
326
                        RENDREN_O                                <= 0;
327
                        rResetVertexCount  <= 0;
328
                        GACK_O                                   <= 0;
329
                        //STDONE_O                                       <= 0;
330
                        oHostDataAvailable    <= 0;
331
 
332
                        rHostNextState <= `HOST_WAIT_SCENE_PARAMS;
333
                end
334
                //----------------------------------------
335
                `HOST_WAIT_SCENE_PARAMS:
336
                begin
337
                        rWBMEnable            <= ~wWBMDone;
338
                   rInitiaReadAddr       <= 0;
339
                        rWBMReset             <= 0;
340
                        oMemSelect            <= `SELECT_SCENE_MEM;
341
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
342
                        MST_O                   <= 1;
343
                        rInitialWriteAddress  <= 0;
344
         rSetWriteAddr         <= 0;
345
                        rCoreBroadCast        <= 1;
346
                        rIncCoreSelect        <= 0;
347
                        RENDREN_O                                <= 0;
348
                        rResetVertexCount  <= 0;
349
                        GACK_O                                   <= 0;
350
                        //STDONE_O                                       <= 0;
351
                        oHostDataAvailable    <= 0;
352
 
353
                        if ( wWBMDone && ~wLastParameter )
354
                                rHostNextState <= `HOST_WRITE_SCENE_PARAMS;
355
                        else if (wWBMDone && wLastParameter )
356
                                rHostNextState <= `HOST_PREPARE_CORE_CONFIG;
357
                        else
358
                                rHostNextState <= `HOST_WAIT_SCENE_PARAMS;
359
                end
360
                //----------------------------------------
361
                /*
362
                        This state set the read Write Address pointer to
363
                        CREG_PIXEL_2D_INITIAL_POSITION memory position,
364
                        also selects the scene MEM from the external MEM
365
                        MUX.
366
                */
367
                `HOST_PREPARE_CORE_CONFIG:
368
                begin
369
                        rWBMEnable            <= 0;
370
                   rInitiaReadAddr       <= 0;
371
                        rWBMReset             <= 0;
372
                        oMemSelect            <= `SELECT_SCENE_MEM;                                             //We are reading from the scene memory
373
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;                                //We will write to the DATA section of the core MEM
374
                        MST_O                   <= 1;                                                                                   //Keep master signal in 1 for now
375
                        rInitialWriteAddress  <= `CREG_PIXEL_2D_INITIAL_POSITION;       //The address from which to start wrting @ the cores
376
         rSetWriteAddr         <= 1;                                                                                    //Set to use the initial write address bellow
377
                        rCoreBroadCast        <= 0;                                                                                      //Set to zero to unicast, starting from core 0
378
                        rIncCoreSelect        <= 0;                                                                                      //Set to unicast to the next core
379
                        RENDREN_O                                <= 0;
380
                        rResetVertexCount  <= 0;
381
                        GACK_O                                   <= 0;
382
                        //STDONE_O                                       <= 0;
383
                        oHostDataAvailable    <= 0;
384
 
385
 
386
                        rHostNextState <= `HOST_UNICAST_CORE_CONFIG;
387
                end
388
 
389
                //----------------------------------------
390
                `HOST_UNICAST_CORE_CONFIG:
391
                begin
392
                        rWBMEnable            <= 1;
393
                   rInitiaReadAddr       <= 0;
394
                        rWBMReset             <= 0;
395
                        oMemSelect            <= `SELECT_SCENE_MEM;
396
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
397
                        MST_O                   <= 1;
398
                        rInitialWriteAddress  <= 0;
399
         rSetWriteAddr         <= 0;
400
                        rCoreBroadCast        <= 0;
401
                        rIncCoreSelect        <= 0;
402
                        RENDREN_O                                <= 0;
403
                        rResetVertexCount  <= 0;
404
                        GACK_O                                   <= 0;
405
                        //STDONE_O                                       <= 0;
406
                        oHostDataAvailable    <= 0;
407
 
408
                        rHostNextState <= `HOST_WAIT_CORE_CONFIG;
409
                end
410
                //----------------------------------------
411
                `HOST_WAIT_CORE_CONFIG:
412
                begin
413
                        rWBMEnable            <= ~wWBMDone;
414
                   rInitiaReadAddr       <= 0;
415
                        rWBMReset             <= 0;
416
                        oMemSelect            <= `SELECT_SCENE_MEM;
417
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
418
                        MST_O                   <= 1;
419
                        rInitialWriteAddress  <= 0;
420
         rSetWriteAddr         <= 0;
421
                        rCoreBroadCast        <= 0;
422
                        rIncCoreSelect        <= 0;
423
                        RENDREN_O                                <= 0;
424
                        rResetVertexCount  <= 0;
425
                        GACK_O                                   <= 0;
426
                        //STDONE_O                                       <= 0;
427
                        oHostDataAvailable    <= 0;
428
 
429
 
430
                        if (wWBMDone && !(oReadAddress % 2))
431
                                rHostNextState <= `HOST_UNICAST_CORE_CONFIG;
432
                        else if (wWBMDone && (oReadAddress % 2) )
433
                                rHostNextState <= `HOST_PREPARE_NEXT_CORE_CONFIG;
434
                        else
435
                                rHostNextState <= `HOST_WAIT_CORE_CONFIG;
436
 
437
                end
438
                //----------------------------------------
439
                /*
440
                        Reset the WBM to tell it to start reading
441
                        from address 0 at the Geometry memory.
442
                */
443
                `HOST_PREPARE_NEXT_CORE_CONFIG:
444
                begin
445
                        rWBMEnable            <= 0;
446
                   rInitiaReadAddr       <= 0;
447
                        rWBMReset             <= 0;
448
                        oMemSelect            <= `SELECT_GEO_MEM;
449
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
450
                        MST_O                   <= 0;                                                                                    //The master signal goes to zero until request
451
                        rInitialWriteAddress  <= `CREG_PIXEL_2D_INITIAL_POSITION;       //Write starting from this location on the cores
452
         rSetWriteAddr         <= 1;                                                                                    //Set to use the initial write address bellow
453
                        rCoreBroadCast        <= 0;
454
                        rIncCoreSelect        <= 1;                                                                                     //Moving to configure the next core now
455
                        RENDREN_O                                <= 0;
456
                        rResetVertexCount  <= 0;
457
                        GACK_O                                   <= 0;
458
                        //STDONE_O                                       <= 0;
459
                        oHostDataAvailable    <= 0;
460
 
461
                        if (wCoreSelect[`MAX_CORES-1] == 1)
462
                                rHostNextState <= `HOST_PREPARE_FOR_GEO_REQUESTS;
463
                        else
464
                                rHostNextState <= `HOST_UNICAST_CORE_CONFIG;
465
                end
466
                //----------------------------------------
467
                /*
468
                        Prepare the write address for the next primitive.
469
 
470
                */
471
                `HOST_PREPARE_FOR_GEO_REQUESTS:
472
                begin
473
                        rWBMEnable            <= 0;                                                              //Do not enable until we are resquested
474
                   rInitiaReadAddr       <= 32'hA;                                                      //Start reading from addr 0 @ GEO MEM
475
                        rWBMReset             <= 1;                                                             //Tell WBM to start reading from the addr bellow
476
                        oMemSelect            <= `SELECT_GEO_MEM;                       //Use external GEO mem for reading
477
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;        //We write to the data MEM @ the cores
478
                        MST_O                   <= 0;                                                            //The master signal goes to zero until request
479
                        rInitialWriteAddress  <= `CREG_V0;                                              //Write starting from this location on the cores
480
         rSetWriteAddr         <= 1;                                                            //Set to use the initial write address bellow
481
                        rCoreBroadCast        <= 1;                                                             //From now on we only broadcast                                 
482
                        rIncCoreSelect        <= 0;                                                              //Ignored during broadcasts     
483
                        RENDREN_O                                <= 0;
484
                        rResetVertexCount  <= 1;
485
                        GACK_O                                   <= 0;
486
                        //STDONE_O                                       <= 0;
487
                        oHostDataAvailable    <= 0;
488
 
489
                        if (iGPUDone)
490
                                rHostNextState <= `HOST_GPU_EXECUTION_DONE;
491
                        else
492
                                rHostNextState <= `HOST_BROADCAST_NEXT_VERTEX;
493
 
494
                end
495
                //----------------------------------------
496
                `HOST_ACK_GEO_REQUEST:
497
                begin
498
                        rWBMEnable            <= 0;                                                              //Do not enable until we are resquested
499
                   rInitiaReadAddr       <= 0;                                                           //Ignored
500
                        rWBMReset             <= 0;                                                              //Ignored
501
                        oMemSelect            <= `SELECT_GEO_MEM;                       //Use external GEO mem for reading
502
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;        //We write to the data MEM @ the cores
503
                        MST_O                   <= 0;                                                            //The master signal goes to zero until request
504
                        rInitialWriteAddress  <= `CREG_V0;                                              //Write starting from this location on the cores
505
         rSetWriteAddr         <= 1;                                                            //Set to use the initial write address bellow
506
                        rCoreBroadCast        <= 1;                                                             //From now on we only broadcast                                 
507
                        rIncCoreSelect        <= 0;                                                              //Ignored during broadcasts     
508
                        RENDREN_O                                <= 0;
509
                        rResetVertexCount       <= 0;
510
                        GACK_O                                   <= 1;
511
                        //STDONE_O                                       <= 0;
512
                        oHostDataAvailable    <= 0;
513
 
514
 
515
                        rHostNextState <= `HOST_BROADCAST_NEXT_VERTEX;
516
 
517
                end
518
                //----------------------------------------
519
                /*
520
                        Send the next primitive to the HUB/SWITCH unit
521
                        so that it gets broadcasted to all the cores
522
                */
523
                `HOST_BROADCAST_NEXT_VERTEX:
524
                begin
525
                        rWBMEnable            <= 1;                                                             //Start the Transmition                                         
526
                   rInitiaReadAddr       <= 0;
527
                        rWBMReset             <= 0;
528
                        oMemSelect            <= `SELECT_GEO_MEM;
529
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
530
                        MST_O                   <= 1;                                                           //Start the Transmition
531
                        rInitialWriteAddress  <= 0;
532
         rSetWriteAddr         <= 0;
533
                        rCoreBroadCast        <= 1;
534
                        rIncCoreSelect        <= 0;
535
                        RENDREN_O                                <= `SELECT_ALL_CORES;
536
                        rResetVertexCount  <= 0;
537
                        GACK_O                                   <= 0;
538
                        //STDONE_O                                       <= 0;
539
                        oHostDataAvailable    <= 0;
540
 
541
                        rHostNextState <= `HOST_WAIT_FOR_VERTEX;
542
 
543
                end
544
                //----------------------------------------
545
                `HOST_WAIT_FOR_VERTEX:
546
                begin
547
                        rWBMEnable            <= ~wWBMDone;                                             //Disable WBM when it is donw                                           
548
                   rInitiaReadAddr       <= 0;
549
                        rWBMReset             <= 0;
550
                        oMemSelect            <= `SELECT_GEO_MEM;
551
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
552
                        MST_O                   <= 1;                                                           //Start the Transmition
553
                        rInitialWriteAddress  <= 0;
554
         rSetWriteAddr         <= 0;
555
                        rCoreBroadCast        <= 1;
556
                        rIncCoreSelect        <= 0;
557
                        RENDREN_O                                <= `SELECT_ALL_CORES;
558
                        rResetVertexCount  <= 0;
559
                        GACK_O                                   <= 0;
560
                        //STDONE_O                                       <= 0;
561
                        oHostDataAvailable    <= 0;
562
 
563
 
564
                        if (wWBMDone & ~wLastVertexInFrame )
565
                                rHostNextState <= `HOST_BROADCAST_NEXT_VERTEX;
566
                        else if (wWBMDone & wLastVertexInFrame )
567
                                rHostNextState <= `HOST_GET_PRIMITIVE_COUNT;
568
                        else
569
                                rHostNextState <= `HOST_WAIT_FOR_VERTEX;
570
 
571
 
572
                        /*
573
                        if (wWBMDone)
574
                                rHostNextState <= `HOST_WAIT_DATA_READ_CONFIRMATION;
575
                        else
576
                                rHostNextState <= `HOST_WAIT_FOR_VERTEX;
577
                                */
578
                end
579
                //----------------------------------------
580
                `HOST_GET_PRIMITIVE_COUNT:
581
                begin
582
                        rWBMEnable            <= 0;                                              //Disable WBM when it is donw                                           
583
                   rInitiaReadAddr       <= 0;
584
                        rWBMReset             <= 0;
585
                        oMemSelect            <= `SELECT_GEO_MEM;
586
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
587
                        MST_O                   <= 1;                                                           //Start the Transmition
588
                        rInitialWriteAddress  <= 0;
589
         rSetWriteAddr         <= 0;
590
                        rCoreBroadCast        <= 1;
591
                        rIncCoreSelect        <= 0;
592
                        RENDREN_O                                <= `SELECT_ALL_CORES;
593
                        rResetVertexCount  <= 0;
594
                        GACK_O                                   <= 0;
595
                        //STDONE_O                                       <= 0;
596
                        oHostDataAvailable    <= 0;//1;
597
 
598
                        if (wVertexCount >= iPrimitiveCount)
599
                                rHostNextState <= `HOST_LAST_PRIMITIVE_REACHED;
600
                        else
601
                                rHostNextState <= `HOST_WAIT_DATA_READ_CONFIRMATION;
602
 
603
                end
604
                //----------------------------------------
605
                /*
606
                        we wait until all the cores are ready for the next primitive,
607
                        this happens when the iHostDataReadConfirmed signal
608
                        gets asserted
609
                */
610
                `HOST_WAIT_DATA_READ_CONFIRMATION:
611
                begin
612
                        rWBMEnable            <= 0;                                                              //Do not enable until we are resquested
613
                   rInitiaReadAddr       <= 0;                                                           //Ignored
614
                        rWBMReset             <= 0;                                                              //Continue from previous read address
615
                        oMemSelect            <= `SELECT_GEO_MEM;                       //Use external GEO mem for reading
616
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;        //We write to the data MEM @ the cores
617
                        MST_O                   <= 0;                                                            //The master signal goes to zero until request
618
                        rInitialWriteAddress  <= `CREG_V0;                                              //Write starting from this location on the cores
619
         rSetWriteAddr         <= 1;                                                            //Set to use the initial write address bellow
620
                        rCoreBroadCast        <= 1;                                                             //From now on we only broadcast                                 
621
                        rIncCoreSelect        <= 0;                                                              //Ignored during broadcasts     
622
                        RENDREN_O                                <= `SELECT_ALL_CORES;
623
                        rResetVertexCount  <= 0;
624
                        GACK_O                                   <= 0;
625
                        //STDONE_O                                       <= 0;
626
                        oHostDataAvailable    <= 1;
627
 
628
                        if ( iHostDataReadConfirmed )
629
                                rHostNextState <= `HOST_ACK_GEO_REQUEST;
630
                        else
631
                                rHostNextState <= `HOST_WAIT_DATA_READ_CONFIRMATION;
632
                end
633
                //----------------------------------------
634
                `HOST_LAST_PRIMITIVE_REACHED:
635
                begin
636
                        rWBMEnable            <= 0;                                                              //Disable WBM when it is donw                                           
637
                   rInitiaReadAddr       <= 32'hA;                                                      //Reset primitive counter to first primitive                                            
638
                        rWBMReset             <= 1;                                                             //Reset primitive counter to first primitive            
639
                        oMemSelect            <= `SELECT_GEO_MEM;
640
                        TGA_O                 <= `TAG_DATA_ADDRESS_TYPE;
641
                        MST_O                   <= 1;
642
                        rInitialWriteAddress  <= 0;
643
         rSetWriteAddr         <= 0;
644
                        rCoreBroadCast        <= 1;
645
                        rIncCoreSelect        <= 0;
646
                        RENDREN_O                                <= `SELECT_ALL_CORES;
647
                        rResetVertexCount     <= 0;                                                      //Reset the vertex count to zero
648
                        GACK_O                                   <= 0;
649
                        //STDONE_O                                       <= 1;
650
                        oHostDataAvailable    <= 0;
651
 
652
 
653 143 diegovalve
 
654 124 diegovalve
                        if (iGPUCommitedResults)
655 143 diegovalve
                        begin
656
 
657
                        `ifndef NO_DISPLAY_STATS
658
                        for (i = 0; i < `MAX_CORES; i = i + 1)
659
                        begin
660
                                $write(".");
661
                        end
662
                        RenderedPixels = RenderedPixels + `MAX_CORES;
663
                        if ( RenderedPixels % iDebugWidth == 0)
664
                                $write("]%d\n[",RenderedPixels / iDebugWidth);
665
                        `endif
666
 
667 124 diegovalve
                                rHostNextState <= `HOST_PREPARE_FOR_GEO_REQUESTS;
668 143 diegovalve
                        end
669 124 diegovalve
                        else
670
                                rHostNextState <= `HOST_LAST_PRIMITIVE_REACHED;
671
                end
672
                //----------------------------------------
673
                `HOST_GPU_EXECUTION_DONE:
674
                begin
675
                        $display("THEIA Execution done in %dns\n",$time-StartTime);
676
                  rWBMEnable            <= 0;
677
                   rInitiaReadAddr       <= 0;
678
                        rWBMReset             <= 0;
679
                        oMemSelect            <= 0;
680
                        TGA_O                 <= 0;
681
                        MST_O                   <= 0;
682
                        rInitialWriteAddress  <= 0;
683
         rSetWriteAddr         <= 0;
684
                        rCoreBroadCast        <= 0;
685
                        rIncCoreSelect        <= 0;
686
                        RENDREN_O                                <= 0;
687
                        rResetVertexCount  <= 0;
688
                        GACK_O                                   <= 0;
689
                        //STDONE_O                                       <= 0;
690
                        oHostDataAvailable    <= 0;
691
 
692
                        rHostNextState <= `HOST_GPU_EXECUTION_DONE;
693
                end
694
                //----------------------------------------
695
                default:
696
                begin
697
 
698
                        rWBMEnable            <= 0;
699
                   rInitiaReadAddr       <= 0;
700
                        rWBMReset             <= 0;
701
                        oMemSelect            <= 0;
702
                        TGA_O                 <= 0;
703
                        MST_O                   <= 0;
704
                        rInitialWriteAddress  <= 0;
705
         rSetWriteAddr         <= 0;
706
                        rCoreBroadCast        <= 0;
707
                        rIncCoreSelect        <= 0;
708
                        RENDREN_O                                <= 0;
709
                        rResetVertexCount  <= 0;
710
                        GACK_O                                   <= 0;
711
                        //STDONE_O                                       <= 0;
712
                        oHostDataAvailable    <= 0;
713
 
714
                        rHostNextState <= `HOST_IDLE;
715
                end
716
                //----------------------------------------
717
                endcase
718
end
719
 
720
endmodule

powered by: WebSVN 2.1.0

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