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 196

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 178 diegovalve
`define HOST_PREPARE_BROADCAST_CREG_MAX_PRIMITIVES  19
65
`define HOST_BROADCAST_CREG_MAX_PRIMITIVES    20
66
`define HOST_WAIT_CREG_MAX_PRIMITIVES     21
67 158 diegovalve
 
68
//---------------------------------------------------------------
69
module Module_Host
70
(
71 174 diegovalve
 input wire                 Clock,
72
 input wire                 Reset,
73
 input wire                 iEnable,
74
 input wire                 iHostDataReadConfirmed,
75
 input wire [`WB_WIDTH-1:0] iMemorySize,
76
 input wire [`WB_WIDTH-1:0] iPrimitiveCount,
77
 
78
 //To Memory
79
 output wire [`WB_WIDTH-1:0] oReadAddress,
80
 input wire [`WB_WIDTH-1:0]  iReadData,
81
 input wire                  iGPUCommitedResults,
82
 
83
 //To Hub/Switch
84
 output reg [`MAX_CORES-1:0]      oCoreSelectMask,
85
 output reg [1:0]                 oMemSelect,
86
 output wire [`WB_WIDTH-1:0]      DAT_O,
87
 output wire [`WB_WIDTH-1:0]      ADR_O,
88
 output reg[1:0]                  TGA_O,
89
 output reg[`MAX_CORES-1:0]       RENDREN_O,
90
 output wire                      CYC_O,
91
 output wire                      STB_O,
92
 output reg                       MST_O,
93
 output wire                      WE_O,
94
 input  wire                      GRDY_I, //This means all the cores are done rading the primitive we send
95
 output reg                       GACK_O, //We set this to ACK that the cored read the primitive
96
 output wire                      STDONE_O,
97
 output reg                       oHostDataAvailable,
98
 input wire                       iGPUDone,
99 178 diegovalve
 output reg                       oRenderDone,
100
 
101
 input wire [`WIDTH-1:0] iWidth,iHeight,
102
 
103 174 diegovalve
 
104
 input wire                       ACK_I
105 158 diegovalve
);
106 174 diegovalve
wire wGPUDone;
107
 
108
//Need this flop to break combinatorial loop asserted by verilator!
109
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD_DONE
110
        (
111
              .Clock(Clock),
112
              .Reset(Reset),
113
              .Enable( 1'b1 ),
114
              .D(iGPUDone),
115
              .Q(wGPUDone)
116
        );
117
 
118
 
119 158 diegovalve
//---------------------------------------------------------------
120
wire wLastPrimitive;
121
assign wLastPrimitive = (wVertexCount >= iPrimitiveCount) ? 1'b1 : 1'b0;
122
assign STDONE_O = wLastPrimitive;
123
 
124
wire  wWBMDone;
125
reg rWBMEnable,rWBMReset,rCoreBroadCast;
126
reg [`WB_WIDTH-1:0] rInitiaReadAddr;
127
wire [`MAX_CORES-1:0] wCoreSelect;
128
wire wLastValidReadAddress;
129
wire [`WB_WIDTH-1:0] wWriteAddress;
130
wire [`WIDTH-1:0] wVertexCount;
131
reg [`WB_WIDTH-1:0] rInitialWriteAddress;
132
reg rSetWriteAddr;
133
reg rIncCoreSelect,rResetVertexCount;
134
//--------------------------------------------------------
135
 
136
assign WE_O = MST_O;
137
 
138 174 diegovalve
//assign oCoreSelectMask = 
139
// (rCoreBroadCast) ? `SELECT_ALL_CORES : wCoreSelect;
140
 
141
 
142
wire wLastCoreSelected;
143
assign wLastCoreSelected = wCoreSelect[`MAX_CORES-1];
144
 
145 158 diegovalve
assign wLastValidReadAddress =
146 174 diegovalve
 (oReadAddress >= iMemorySize) ? 1'b1 : 1'b0;
147 158 diegovalve
 
148
wire wLastParameter;
149
assign wLastParameter = (oReadAddress >= 32'h12) ? 1'b1 : 1'b0;
150
//--------------------------------------------------------
151 174 diegovalve
UPCOUNTER_POSEDGE # (`WB_WIDTH ) UPWADDR
152
 (
153
 .Clock(  Clock                   ),
154
 .Reset(   Reset | rSetWriteAddr  ),
155
 .Enable(  iEnable & wWBMDone     ),
156
 .Initial( rInitialWriteAddress   ),
157
 .Q(       wWriteAddress          )
158
 );
159 158 diegovalve
 
160
 
161 174 diegovalve
UPCOUNTER_POSEDGE # ( 32 ) PRIMCOUNT
162
 (
163
 .Clock(  Clock                   ),
164
 .Reset(   Reset | rResetVertexCount  ),
165
 .Enable(  iEnable & wWBMDone     ),
166
 .Initial( `WIDTH'b1   ),
167
 .Q(       wVertexCount          )
168
 );
169 158 diegovalve
//--------------------------------------------------------
170 174 diegovalve
CIRCULAR_SHIFTLEFT_POSEDGE_EX # (`MAX_CORES ) SHF1
171 158 diegovalve
(
172 174 diegovalve
 .Clock(    Clock             ),
173
 .Reset(    Reset             ),
174
 .Initial( `MAX_CORES'b1      ),
175
 .Enable(   rIncCoreSelect    ),
176
 .O(        wCoreSelect       )
177 158 diegovalve
);
178
//--------------------------------------------------------
179
wire wShortCycle;
180
//For instruction we send 2 packets per cycle
181
//for the other we send 3 packets per cycle
182
assign wShortCycle = (oMemSelect == `SELECT_INST_MEM) ? 1'b1 : 1'b0;
183
 
184 174 diegovalve
WBMaster HOST_WBM
185 158 diegovalve
(
186
.Clock(            Clock             ),
187
.Reset(            Reset | rWBMReset ),
188
.iEnable(          rWBMEnable        ),
189
.iInitialReadAddr( rInitiaReadAddr   ),
190
.iWriteAddr(       wWriteAddress     ),
191
.oReadAddress(     oReadAddress      ),
192
.iReadData(        iReadData         ),
193 174 diegovalve
.iShortFlow(        wShortCycle     ),
194
 
195
 
196 158 diegovalve
.STB_O( STB_O ),
197
.ACK_I( ACK_I ),
198
.CYC_O( CYC_O ),
199
.DAT_O( DAT_O ),
200
.ADR_O( ADR_O ),
201
.oDone( wWBMDone )
202
);
203
 
204
//--------------------------------------------------------
205
// Current State Logic //
206 174 diegovalve
reg [7:0]    rHostCurrentState,rHostNextState;
207
always @(posedge Clock or posedge Reset)
208
begin
209
     if( Reset!=1 )
210
        rHostCurrentState <= rHostNextState;
211
   else
212
    rHostCurrentState <= `HOST_IDLE;
213 158 diegovalve
end
214
//--------------------------------------------------------
215
 
216
reg [63:0] i;
217
reg [63:0] RenderedPixels;
218
wire wLastVertexInFrame;
219
assign wLastVertexInFrame =
220 175 diegovalve
(wVertexCount % `MAX_VERTEX_IN_FRAME == 32'b0 ) ? 1'b1 : 1'b0;
221 158 diegovalve
 
222
 
223 175 diegovalve
reg [63:0] StartTime;
224 158 diegovalve
 
225
// Host Finite State Machine //
226
always @( * )
227 174 diegovalve
 begin
228
 
229
  case (rHostCurrentState)
230
  //----------------------------------------
231
  //Wait for reset sequence to complete,
232
  //Or until we are enabled
233
  `HOST_IDLE:
234
  begin
235 176 diegovalve
//  `ifndef VERILATOR
236 174 diegovalve
   RenderedPixels = 0;
237 176 diegovalve
 // `endif 
238 174 diegovalve
 
239
   rWBMEnable            = 0;
240
   rInitiaReadAddr       = 1; //Start reading from 1, because 0 is the size
241
   rWBMReset             = 0;
242
   oMemSelect            = 0;
243
   TGA_O                 = 0;
244
   MST_O                 = 0;
245
   rInitialWriteAddress  = 0;
246
   rSetWriteAddr         = 0;
247
   //rCoreBroadCast        = 0;
248
   oCoreSelectMask       = wCoreSelect;
249
   rIncCoreSelect        = 0;
250
   RENDREN_O             = 0;
251
   rResetVertexCount     = 0;
252
   GACK_O                = 0;
253
   oHostDataAvailable    = 0;
254 178 diegovalve
        oRenderDone           = 0;
255 174 diegovalve
 
256
   if ( ~Reset & iEnable )
257
   begin
258
    $display("-I- HOST: Broadcasting User code to all Cores\n");
259
    `ifndef VERILATOR
260
    $fflush;
261
    `endif
262
 
263
    rHostNextState = `HOST_WRITE_INSTRUCTION;
264
   end
265
   else
266
    rHostNextState = `HOST_IDLE;
267
  end
268
  //----------------------------------------
269
  //Broadcast the instructions to all the cores
270
  `HOST_WRITE_INSTRUCTION:
271
  begin
272
 
273
   StartTime = $time;
274
 
275
   rWBMEnable            = 1;                            //Enable Wish bone master
276
   rInitiaReadAddr       = 1;                            //Start reading from 1, because 0 is the size
277
   rWBMReset             = 0;                            //No need to reset since we just came from reset
278
   oMemSelect            = `SELECT_INST_MEM;             //Start by sending the instructions
279
   TGA_O                 = `TAG_INSTRUCTION_ADDRESS_TYPE;
280
   MST_O                 = 1;
281
   rInitialWriteAddress  = 0;
282
   rSetWriteAddr         = 0;
283
   //rCoreBroadCast        = 1;
284
   oCoreSelectMask       = `SELECT_ALL_CORES;
285
   rIncCoreSelect        = 0;
286
   RENDREN_O             = 0;
287
   rResetVertexCount     = 0;
288
   GACK_O                = 0;
289 178 diegovalve
   oHostDataAvailable    = 0;
290
   oRenderDone           = 0;
291 174 diegovalve
 
292
   rHostNextState = `HOST_WAIT_INSTRUCTION;
293
  end
294
  //----------------------------------------
295
  `HOST_WAIT_INSTRUCTION:
296
  begin
297
   rWBMEnable            = ~wWBMDone;
298
   rInitiaReadAddr       = 0;
299
   rWBMReset             = 0;
300
   oMemSelect            = `SELECT_INST_MEM;
301
   TGA_O                 = `TAG_INSTRUCTION_ADDRESS_TYPE;
302
   MST_O                 = 1;
303
   rInitialWriteAddress  = 0;
304
   rSetWriteAddr         = 0;
305
   //rCoreBroadCast        = 1;
306
   oCoreSelectMask       = `SELECT_ALL_CORES;
307
   rIncCoreSelect        = 0;
308
   RENDREN_O             = 0;
309
   rResetVertexCount     = 0;
310
   GACK_O                = 0;
311
   oHostDataAvailable    = 0;
312 178 diegovalve
        oRenderDone           = 0;
313 174 diegovalve
 
314
   if ( wWBMDone && ~wLastValidReadAddress )
315
    rHostNextState = `HOST_WRITE_INSTRUCTION;
316
   else if (wWBMDone && wLastValidReadAddress )
317
    rHostNextState = `HOST_INITIAL_SCENE_PARAMS_STAGE;
318
   else
319
    rHostNextState = `HOST_WAIT_INSTRUCTION;
320
  end
321
  //----------------------------------------
322
  /*
323
   Make sure to read-pointer points to the
324
   first memory address at te params memory
325
  */
326
  `HOST_INITIAL_SCENE_PARAMS_STAGE:
327
  begin
328
   rWBMEnable            = 0;
329
   rInitiaReadAddr       = 1;                       //Start reading from 1, because 0 is the size
330
   rWBMReset             = 1;
331
   oMemSelect            = `SELECT_SCENE_MEM;       //We are reading from the scene memory
332
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;  //We will write to the DATA section of the core MEM
333
   MST_O                 = 1;                       //Keep master signal in 1 for now
334
   rInitialWriteAddress  = 0;                       //We start writing from address zero now
335
   rSetWriteAddr         = 1;
336
   //rCoreBroadCast        = 1;                       //Set to zero to unicast, starting from core 0
337
   oCoreSelectMask       = `SELECT_ALL_CORES;
338
   rIncCoreSelect        = 0;                       //Set to unicast to the next core
339
   RENDREN_O             = 0;
340
   rResetVertexCount     = 0;
341
   GACK_O                = 0;
342
   oHostDataAvailable    = 0;
343 178 diegovalve
        oRenderDone           = 0;
344 174 diegovalve
 
345
   $display("-I- HOST: Configuring Core Mask %b\n",oCoreSelectMask);
346
   `ifndef VERILATOR
347
   $fflush;
348
   `endif
349
 
350
 
351
   rHostNextState = `HOST_WRITE_SCENE_PARAMS;
352
  end
353
 
354
  //----------------------------------------
355
  //Broadcast the instructions to all the cores
356
  `HOST_WRITE_SCENE_PARAMS:
357
  begin
358
   rWBMEnable            = 1;
359
   rInitiaReadAddr       = 0;
360
   rWBMReset             = 0;
361
   oMemSelect            = `SELECT_SCENE_MEM;
362
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
363
   MST_O                 = 1;
364
   rInitialWriteAddress  = 0;
365
   rSetWriteAddr         = 0;
366
   //rCoreBroadCast        = 1;
367
   oCoreSelectMask       = `SELECT_ALL_CORES;
368
   rIncCoreSelect        = 0;
369
   RENDREN_O             = 0;
370
   rResetVertexCount     = 0;
371
   GACK_O                = 0;
372
   oHostDataAvailable    = 0;
373 178 diegovalve
        oRenderDone           = 0;
374 174 diegovalve
 
375
   rHostNextState = `HOST_WAIT_SCENE_PARAMS;
376
  end
377
  //----------------------------------------
378
  `HOST_WAIT_SCENE_PARAMS:
379
  begin
380
   rWBMEnable            = ~wWBMDone;
381
   rInitiaReadAddr       = 0;
382
   rWBMReset             = 0;
383
   oMemSelect            = `SELECT_SCENE_MEM;
384
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
385
   MST_O                 = 1;
386
   rInitialWriteAddress  = 0;
387
   rSetWriteAddr         = 0;
388
   oCoreSelectMask       = `SELECT_ALL_CORES;
389
   rIncCoreSelect        = 0;
390
   RENDREN_O             = 0;
391
   rResetVertexCount     = 0;
392
   GACK_O                = 0;
393
   oHostDataAvailable    = 0;
394 178 diegovalve
        oRenderDone           = 0;
395 174 diegovalve
 
396
   if ( wWBMDone && ~wLastParameter )
397
    rHostNextState = `HOST_WRITE_SCENE_PARAMS;
398
   else if (wWBMDone && wLastParameter )
399
    rHostNextState = `HOST_PREPARE_CORE_CONFIG;
400
   else
401
    rHostNextState = `HOST_WAIT_SCENE_PARAMS;
402
  end
403
  //----------------------------------------
404
  /*
405
   This state set the read Write Address pointer to
406
   CREG_PIXEL_2D_INITIAL_POSITION memory position,
407
   also selects the scene MEM from the external MEM
408
   MUX.
409
  */
410
  `HOST_PREPARE_CORE_CONFIG:
411
  begin
412
   rWBMEnable            = 0;
413
   rInitiaReadAddr       = 0;
414
   rWBMReset             = 0;
415 175 diegovalve
   oMemSelect            = `SELECT_SCENE_MEM;                       //We are reading from the scene memory
416
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;                  //We will write to the DATA section of the core MEM
417
   MST_O                 = 1;                                       //Keep master signal in 1 for now
418
   rInitialWriteAddress  = {16'b0,`CREG_PIXEL_2D_INITIAL_POSITION}; //The address from which to start wrting @ the cores
419
   rSetWriteAddr         = 1;                                       //Set to use the initial write address bellow
420 174 diegovalve
   oCoreSelectMask       = wCoreSelect;
421 175 diegovalve
   rIncCoreSelect        = 0;                                       //Set to unicast to the next core
422 174 diegovalve
   RENDREN_O             = 0;
423
   rResetVertexCount     = 0;
424
   GACK_O                = 0;
425
   oHostDataAvailable    = 0;
426 178 diegovalve
        oRenderDone           = 0;
427 174 diegovalve
 
428
 
429
   rHostNextState = `HOST_UNICAST_CORE_CONFIG;
430
  end
431
 
432
  //----------------------------------------
433
  `HOST_UNICAST_CORE_CONFIG:
434
  begin
435
   rWBMEnable            = 1;
436
   rInitiaReadAddr       = 0;
437
   rWBMReset             = 0;
438
   oMemSelect            = `SELECT_SCENE_MEM;
439
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
440
   MST_O                 = 1;
441
   rInitialWriteAddress  = 0;
442
   rSetWriteAddr         = 0;
443
   //rCoreBroadCast        = 0;
444
   oCoreSelectMask       = wCoreSelect;
445
   rIncCoreSelect        = 0;
446
   RENDREN_O             = 0;
447
   rResetVertexCount     = 0;
448
   GACK_O                = 0;
449
   oHostDataAvailable    = 0;
450 178 diegovalve
        oRenderDone           = 0;
451 174 diegovalve
 
452
   rHostNextState = `HOST_WAIT_CORE_CONFIG;
453
  end
454
  //----------------------------------------
455
  `HOST_WAIT_CORE_CONFIG:
456
  begin
457
   rWBMEnable            = ~wWBMDone;
458
   rInitiaReadAddr       = 0;
459
   rWBMReset             = 0;
460
   oMemSelect            = `SELECT_SCENE_MEM;
461
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
462
   MST_O                 = 1;
463
   rInitialWriteAddress  = 0;
464
   rSetWriteAddr         = 0;
465
   //rCoreBroadCast        = 0;
466
   oCoreSelectMask       = wCoreSelect;
467
   rIncCoreSelect        = 0;
468
   RENDREN_O             = 0;
469
   rResetVertexCount     = 0;
470
   GACK_O                = 0;
471
   oHostDataAvailable    = 0;
472 178 diegovalve
        oRenderDone           = 0;
473 174 diegovalve
 
474
 
475 175 diegovalve
   if (wWBMDone && ((oReadAddress % 2) == `WB_WIDTH'b0))
476 174 diegovalve
    rHostNextState = `HOST_UNICAST_CORE_CONFIG;
477 175 diegovalve
   else if (wWBMDone && ((oReadAddress % 2) != `WB_WIDTH'b0))
478 174 diegovalve
    rHostNextState = `HOST_PREPARE_NEXT_CORE_CONFIG;
479
   else
480
    rHostNextState = `HOST_WAIT_CORE_CONFIG;
481
 
482
  end
483
  //----------------------------------------
484
  /*
485
   Reset the WBM to tell it to start reading
486
   from address 0 at the Geometry memory.
487
  */
488
  `HOST_PREPARE_NEXT_CORE_CONFIG:
489
  begin
490
   rWBMEnable            = 0;
491
   rInitiaReadAddr       = 0;
492
   rWBMReset             = 0;
493
   oMemSelect            = `SELECT_GEO_MEM;
494
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
495 175 diegovalve
   MST_O                 = 0;                                       //The master signal goes to zero until request
496
   rInitialWriteAddress  = {16'b0,`CREG_PIXEL_2D_INITIAL_POSITION}; //Write starting from this location on the cores
497
   rSetWriteAddr         = 1;                                       //Set to use the initial write address bellow
498 174 diegovalve
   oCoreSelectMask       = wCoreSelect;
499 175 diegovalve
   rIncCoreSelect        = 1;                                       //Moving to configure the next core now
500 174 diegovalve
   RENDREN_O             = 0;
501
   rResetVertexCount     = 0;
502
   GACK_O                = 0;
503
   oHostDataAvailable    = 0;
504 178 diegovalve
        oRenderDone           = 0;
505 174 diegovalve
 
506 178 diegovalve
   if (wLastCoreSelected)
507
    rHostNextState = `HOST_PREPARE_BROADCAST_CREG_MAX_PRIMITIVES;
508 174 diegovalve
   else
509
    rHostNextState = `HOST_UNICAST_CORE_CONFIG;
510
  end
511
  //----------------------------------------
512 178 diegovalve
  `HOST_PREPARE_BROADCAST_CREG_MAX_PRIMITIVES:
513
  begin
514
   rWBMEnable            = 0;                                       //Do not enable until we are resquested
515
   rInitiaReadAddr       = 32'd6;                                                                                         //Start reading from here, it has the # of primites
516
   rWBMReset             = 1;                                       //Tell WBM to start reading from the addr bellow
517
   oMemSelect            = `SELECT_GEO_MEM;                         //We are reading from the geometry memory
518
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;                  //We will write to the DATA section of the core MEM
519
   MST_O                 = 0;                                       //Keep master signal in 0 for now
520
   rInitialWriteAddress  = {16'b0,`CREG_MAX_PRIMITIVES};            //The address from which to start wrting @ the cores
521
   rSetWriteAddr         = 1;                                       //Set to use the initial write address bellow
522
   oCoreSelectMask       = `SELECT_ALL_CORES;
523
   rIncCoreSelect        = 0;                                       //Set to unicast to the next core
524
   RENDREN_O             = 0;
525
   rResetVertexCount     = 0;
526
   GACK_O                = 0;
527
   oHostDataAvailable    = 0;
528
        oRenderDone           = 0;
529
 
530
 
531
   rHostNextState = `HOST_BROADCAST_CREG_MAX_PRIMITIVES;
532
        end
533
        //----------------------------------------
534
        `HOST_BROADCAST_CREG_MAX_PRIMITIVES:
535
        begin
536
        rWBMEnable            = 1;
537
   rInitiaReadAddr       = 0;
538
   rWBMReset             = 0;
539
   oMemSelect            = `SELECT_GEO_MEM;
540
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
541
   MST_O                 = 1;
542
   rInitialWriteAddress  = 0;
543
   rSetWriteAddr         = 0;
544
   oCoreSelectMask       = `SELECT_ALL_CORES;
545
   rIncCoreSelect        = 0;
546
   RENDREN_O             = 0;
547
   rResetVertexCount     = 0;
548
   GACK_O                = 0;
549
   oHostDataAvailable    = 0;
550
        oRenderDone           = 0;
551
 
552
   rHostNextState = `HOST_WAIT_CREG_MAX_PRIMITIVES;
553
  end
554
  //----------------------------------------
555
  `HOST_WAIT_CREG_MAX_PRIMITIVES:
556
  begin
557
   rWBMEnable            = ~wWBMDone;
558
   rInitiaReadAddr       = 0;
559
   rWBMReset             = 0;
560
   oMemSelect            = `SELECT_GEO_MEM;
561
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
562
   MST_O                 = 1;
563
   rInitialWriteAddress  = 0;
564
   rSetWriteAddr         = 0;
565
   oCoreSelectMask       = `SELECT_ALL_CORES;
566
   rIncCoreSelect        = 0;
567
   RENDREN_O             = 0;
568
   rResetVertexCount     = 0;
569
   GACK_O                = 0;
570
   oHostDataAvailable    = 0;
571
        oRenderDone           = 0;
572
 
573
 
574
   if (wWBMDone )
575
         rHostNextState = `HOST_PREPARE_FOR_GEO_REQUESTS;
576
   else
577
    rHostNextState = `HOST_WAIT_CREG_MAX_PRIMITIVES;
578
 
579
  end
580
  //----------------------------------------
581 174 diegovalve
  /*
582
   Prepare the write address for the next primitive.
583
 
584
  */
585
  `HOST_PREPARE_FOR_GEO_REQUESTS:
586
  begin
587
   rWBMEnable            = 0;                      //Do not enable until we are resquested
588
   rInitiaReadAddr       = 32'hA;                  //Start reading from addr 0 @ GEO MEM
589
   rWBMReset             = 1;                      //Tell WBM to start reading from the addr bellow
590
   oMemSelect            = `SELECT_GEO_MEM;        //Use external GEO mem for reading
591
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE; //We write to the data MEM @ the cores
592
   MST_O                 = 0;                      //The master signal goes to zero until request
593 175 diegovalve
   rInitialWriteAddress  = {16'b0,`CREG_V0};       //Write starting from this location on the cores
594 174 diegovalve
   rSetWriteAddr         = 1;                      //Set to use the initial write address bellow
595
   oCoreSelectMask       = `SELECT_ALL_CORES;
596
   rIncCoreSelect        = 0;                      //Ignored during broadcasts 
597
   RENDREN_O             = 0;
598
   rResetVertexCount     = 1;
599
   GACK_O                = 0;
600
   oHostDataAvailable    = 0;
601 178 diegovalve
        oRenderDone           = 0;
602 174 diegovalve
 
603 178 diegovalve
   if (RenderedPixels >= (iWidth*iHeight))//(wGPUDone)
604 174 diegovalve
    rHostNextState = `HOST_GPU_EXECUTION_DONE;
605
   else
606
    rHostNextState = `HOST_BROADCAST_NEXT_VERTEX;
607
 
608
  end
609
  //----------------------------------------
610
  `HOST_ACK_GEO_REQUEST:
611
  begin
612
   rWBMEnable            = 0;                      //Do not enable until we are resquested
613
   rInitiaReadAddr       = 0;                      //Ignored
614
   rWBMReset             = 0;                      //Ignored
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 175 diegovalve
   rInitialWriteAddress  = {16'b0,`CREG_V0};       //Write starting from this location on the cores
619 174 diegovalve
   rSetWriteAddr         = 1;                      //Set to use the initial write address bellow
620
   oCoreSelectMask       = `SELECT_ALL_CORES;
621
   rIncCoreSelect        = 0;                      //Ignored during broadcasts 
622
   RENDREN_O             = 0;
623
   rResetVertexCount     = 0;
624
   GACK_O                = 1;
625
   oHostDataAvailable    = 0;
626 178 diegovalve
        oRenderDone           = 0;
627 174 diegovalve
 
628
 
629
   rHostNextState = `HOST_BROADCAST_NEXT_VERTEX;
630
 
631
  end
632
  //----------------------------------------
633
  /*
634
   Send the next primitive to the HUB/SWITCH unit
635
   so that it gets broadcasted to all the cores
636
  */
637
  `HOST_BROADCAST_NEXT_VERTEX:
638
  begin
639
   rWBMEnable            = 1;                       //Start the Transmition      
640
   rInitiaReadAddr       = 0;
641
   rWBMReset             = 0;
642
   oMemSelect            = `SELECT_GEO_MEM;
643
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
644
   MST_O                 = 1;                       //Start the Transmition
645
   rInitialWriteAddress  = 0;
646
   rSetWriteAddr         = 0;
647
   //rCoreBroadCast        = 1;        
648
   oCoreSelectMask       = `SELECT_ALL_CORES;
649
   rIncCoreSelect        = 0;
650
   RENDREN_O             = `SELECT_ALL_CORES;
651
   rResetVertexCount     = 0;
652
   GACK_O                = 0;
653
   oHostDataAvailable    = 0;
654 178 diegovalve
        oRenderDone           = 0;
655 174 diegovalve
 
656
   rHostNextState = `HOST_WAIT_FOR_VERTEX;
657
 
658
  end
659
  //----------------------------------------
660
  `HOST_WAIT_FOR_VERTEX:
661
  begin
662
   rWBMEnable            = ~wWBMDone;              //Disable WBM when it is donw      
663
   rInitiaReadAddr       = 0;
664
   rWBMReset             = 0;
665
   oMemSelect            = `SELECT_GEO_MEM;
666
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
667
   MST_O                 = 1;                      //Start the Transmition
668
   rInitialWriteAddress  = 0;
669
   rSetWriteAddr         = 0;
670
   //rCoreBroadCast        = 1; 
671
   oCoreSelectMask       = `SELECT_ALL_CORES;
672
   rIncCoreSelect        = 0;
673
   RENDREN_O             = `SELECT_ALL_CORES;
674
   rResetVertexCount     = 0;
675
   GACK_O                = 0;
676
   oHostDataAvailable    = 0;
677 178 diegovalve
        oRenderDone           = 0;
678 174 diegovalve
 
679
 
680
   if (wWBMDone & ~wLastVertexInFrame )
681
    rHostNextState = `HOST_BROADCAST_NEXT_VERTEX;
682
   else if (wWBMDone & wLastVertexInFrame )
683
    rHostNextState = `HOST_GET_PRIMITIVE_COUNT;
684
   else
685
    rHostNextState = `HOST_WAIT_FOR_VERTEX;
686
 
687
  end
688
  //----------------------------------------
689
  `HOST_GET_PRIMITIVE_COUNT:
690
  begin
691
   rWBMEnable            = 0;                      //Disable WBM when it is donw      
692
   rInitiaReadAddr       = 0;
693
   rWBMReset             = 0;
694
   oMemSelect            = `SELECT_GEO_MEM;
695
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
696
   MST_O                 = 1;                      //Start the Transmition
697
   rInitialWriteAddress  = 0;
698
   rSetWriteAddr         = 0;
699
   oCoreSelectMask       = `SELECT_ALL_CORES;
700
   rIncCoreSelect        = 0;
701
   RENDREN_O             = `SELECT_ALL_CORES;
702
   rResetVertexCount     = 0;
703
   GACK_O                = 0;
704
   oHostDataAvailable    = 0;//1;
705 178 diegovalve
        oRenderDone           = 0;
706 174 diegovalve
 
707
   if (wVertexCount >= iPrimitiveCount)
708
    rHostNextState = `HOST_LAST_PRIMITIVE_REACHED;
709
   else
710
    rHostNextState = `HOST_WAIT_DATA_READ_CONFIRMATION;
711
 
712
  end
713
  //----------------------------------------
714
  /*
715
   we wait until all the cores are ready for the next primitive,
716
   this happens when the iHostDataReadConfirmed signal
717
   gets asserted
718
  */
719
  `HOST_WAIT_DATA_READ_CONFIRMATION:
720
  begin
721
   rWBMEnable            = 0;                      //Do not enable until we are resquested
722
   rInitiaReadAddr       = 0;                      //Ignored
723
   rWBMReset             = 0;                      //Continue from previous read address
724
   oMemSelect            = `SELECT_GEO_MEM;        //Use external GEO mem for reading
725
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE; //We write to the data MEM @ the cores
726
   MST_O                 = 0;                      //The master signal goes to zero until request
727 175 diegovalve
   rInitialWriteAddress  = {16'b0,`CREG_V0};       //Write starting from this location on the cores
728 174 diegovalve
   rSetWriteAddr         = 1;                      //Set to use the initial write address bellow
729
   oCoreSelectMask       = `SELECT_ALL_CORES;
730
   rIncCoreSelect        = 0;                      //Ignored during broadcasts 
731
   RENDREN_O             = `SELECT_ALL_CORES;
732
   rResetVertexCount     = 0;
733
   GACK_O                = 0;
734
    oHostDataAvailable   = 1;
735 178 diegovalve
         oRenderDone           = 0;
736 174 diegovalve
 
737
   if ( iHostDataReadConfirmed )
738
    rHostNextState = `HOST_ACK_GEO_REQUEST;
739
   else
740
    rHostNextState = `HOST_WAIT_DATA_READ_CONFIRMATION;
741
  end
742
  //----------------------------------------
743
  `HOST_LAST_PRIMITIVE_REACHED:
744
  begin
745
   rWBMEnable            = 0;                 //Disable WBM when it is donw      
746
   rInitiaReadAddr       = 32'hA;             //Reset primitive counter to first primitive      
747
   rWBMReset             = 1;                 //Reset primitive counter to first primitive  
748
   oMemSelect            = `SELECT_GEO_MEM;
749
   TGA_O                 = `TAG_DATA_ADDRESS_TYPE;
750
   MST_O                 = 1;
751
   rInitialWriteAddress  = 0;
752
   rSetWriteAddr         = 0;
753
   oCoreSelectMask       = `SELECT_ALL_CORES;
754
   rIncCoreSelect        = 0;
755
   RENDREN_O             = `SELECT_ALL_CORES;
756
   rResetVertexCount     = 0;                  //Reset the vertex count to zero
757
   GACK_O                = 0;
758
   oHostDataAvailable    = 0;
759 178 diegovalve
        oRenderDone           = 0;
760 158 diegovalve
 
761 174 diegovalve
 
762
 
763
   if (iGPUCommitedResults)
764
   begin
765 176 diegovalve
  // `ifndef VERILATOR
766 174 diegovalve
   `ifndef NO_DISPLAY_STATS
767
   for (i = 0; i < `MAX_CORES; i = i + 1)
768
   begin
769
    $write(".");
770
    `ifndef VERILATOR
771
    $fflush;
772
    `endif
773
   end
774
 
775
    RenderedPixels = RenderedPixels + `MAX_CORES;
776 176 diegovalve
        /* verilator lint_off WIDTH */
777 178 diegovalve
    if ( RenderedPixels % iWidth == 0)
778 176 diegovalve
        begin
779
 
780 178 diegovalve
     $write("]%d\n[",RenderedPixels / iWidth);
781 176 diegovalve
 
782 178 diegovalve
     `ifndef VERILATOR
783
     $fflush;
784
     `endif
785 176 diegovalve
        end
786
        /* verilator lint_on WIDTH */
787
 
788 174 diegovalve
    `endif
789 176 diegovalve
  // `endif 
790 158 diegovalve
 
791 174 diegovalve
    rHostNextState = `HOST_PREPARE_FOR_GEO_REQUESTS;
792
   end
793
   else
794
    rHostNextState = `HOST_LAST_PRIMITIVE_REACHED;
795
  end
796
  //----------------------------------------
797
  `HOST_GPU_EXECUTION_DONE:
798
  begin
799 178 diegovalve
   $display("THEIA Execution done in %dns\n",$time-StartTime);
800 174 diegovalve
   rWBMEnable            = 0;
801
   rInitiaReadAddr       = 0;
802
   rWBMReset             = 0;
803
   oMemSelect            = 0;
804
   TGA_O                 = 0;
805
   MST_O                 = 0;
806
   rInitialWriteAddress  = 0;
807
   rSetWriteAddr         = 0;
808
   oCoreSelectMask       = wCoreSelect;
809
   rIncCoreSelect        = 0;
810
   RENDREN_O             = 0;
811
   rResetVertexCount     = 0;
812
   GACK_O                = 0;
813
   oHostDataAvailable    = 0;
814 178 diegovalve
        oRenderDone           = 1;
815 174 diegovalve
 
816
   rHostNextState = `HOST_GPU_EXECUTION_DONE;
817
  end
818
  //----------------------------------------
819
  default:
820
  begin
821
 
822
   rWBMEnable             = 0;
823
   rInitiaReadAddr        = 0;
824
   rWBMReset              = 0;
825
   oMemSelect             = 0;
826
   TGA_O                  = 0;
827
   MST_O                  = 0;
828
   rInitialWriteAddress   = 0;
829
   rSetWriteAddr          = 0;
830
   oCoreSelectMask       = wCoreSelect;
831
   rIncCoreSelect         = 0;
832
   RENDREN_O              = 0;
833
   rResetVertexCount      = 0;
834
   GACK_O                 = 0;
835
   oHostDataAvailable     = 0;
836 178 diegovalve
        oRenderDone           = 0;
837 174 diegovalve
 
838
   rHostNextState = `HOST_IDLE;
839
  end
840
  //----------------------------------------
841
  endcase
842
end
843
 
844 158 diegovalve
endmodule

powered by: WebSVN 2.1.0

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