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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [rtl/] [Module_Host.v] - Blame information for rev 176

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

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

powered by: WebSVN 2.1.0

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