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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.2/] [rtl/] [TOP/] [Theia_Core.v] - Blame information for rev 95

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

Line No. Rev Author Line
1 76 diegovalve
/**********************************************************************************
2
Theia, Ray Cast Programable graphic Processing Unit.
3
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
4
 
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
9
 
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
 
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
19
***********************************************************************************/
20
 
21
/**********************************************************************************
22
Description:
23
 This is the top level block for THEIA.
24
 THEIA core has 5 main logical blocks called Units.
25
 This module implements the interconections between the Units.
26
 
27
 Units:
28
  > EXE: Mananges execution logic for the SHADERS.
29
  > GEO: Manages geometry data structures.
30
  > IO: Input/Output (Wishbone).
31
  > MEM: Internal memory, separate for Instructions and data.
32
  > CONTROL: Main control Finite state machine.
33
 
34
 Internal Buses:
35
        THEIA has separate instruction and data buses.
36
        THEIA avoids using tri-state buses by having separate input/output
37
        for each bus.
38
        There are 2 separate data buses since the Data memory
39
        has a Dual read channel.
40
   Please see the MEM unit chapter in the documentation for more details.
41
 
42
 External Buses:
43
        External buses are managed by the IO Unit.
44
        External buses follow the wishbone protocol.
45
        Please see the IO unit chapter in the documentation for more details.
46
**********************************************************************************/
47
 
48
`timescale 1ns / 1ps
49
`include "aDefinitions.v"
50
 
51
module THEIACORE
52
(
53
 
54
input wire                    CLK_I,    //Input clock
55
input wire                    RST_I,    //Input reset
56
//Theia Interfaces
57
input wire                    MST_I,    //Master signal, THEIA enters configuration mode
58
                                       //when this gets asserted (see documentation)
59
//Wish Bone Interface
60
input wire [`WB_WIDTH-1:0]    DAT_I,     //Input data bus  (Wishbone)
61
output wire [`WB_WIDTH-1:0]   DAT_O,     //Output data bus (Wishbone)
62
input wire                    ACK_I,    //Input ack
63
output wire                   ACK_O,    //Output ack
64
output wire [`WB_WIDTH-1:0]   ADR_O,     //Output address
65
input wire [`WB_WIDTH-1:0]    ADR_I,     //Input address
66
output wire                   WE_O,             //Output write enable
67
input wire                    WE_I,    //Input write enable
68
output wire                   STB_O,    //Strobe signal, see wishbone documentation
69
input wire                    STB_I,    //Strobe signal, see wishbone documentation
70
output wire                   CYC_O,    //Bus cycle signal, see wishbone documentation
71
input wire                    CYC_I,   //Bus cycle signal, see wishbone documentation
72
output wire     [1:0]             TGC_O,   //Bus cycle tag, see THEAI documentation
73
input wire [1:0]              TGA_I,   //Input address tag, see THEAI documentation
74
output wire [1:0]             TGA_O,   //Output address tag, see THEAI documentation
75
input wire      [1:0]             TGC_I,   //Bus cycle tag, see THEAI documentation
76
input wire                    GNT_I,   //Bus arbiter 'Granted' signal, see THEAI documentation
77
input wire                    RENDREN_I,
78
 
79
`ifdef DEBUG
80
input wire[`MAX_CORES-1:0]    iDebug_CoreID,
81
`endif
82
//Control Register
83
input wire [15:0]                         CREG_I,
84
output wire                   DONE_O
85
 
86
 
87
);
88
 
89
//Alias this signals
90
wire Clock,Reset;
91
assign Clock = CLK_I;
92
assign Reset = RST_I;
93 82 diegovalve
 
94
wire                              wIO_Busy;
95 76 diegovalve
wire [`DATA_ROW_WIDTH-1:0]                        wEXE_2__MEM_WriteData;
96
wire [`DATA_ROW_WIDTH-1:0]                        wUCODE_RAMBus;
97
wire [`DATA_ADDRESS_WIDTH-1:0]    wEXE_2__MEM_wDataWriteAddress;
98
wire                              w2IO__AddrIsImm;
99
wire [`DATA_ADDRESS_WIDTH-1:0]    wUCODE_RAMAddress;
100
wire [`DATA_ADDRESS_WIDTH-1:0]    w2IO__Adr_O_Pointer;
101
wire [`DATA_ADDRESS_WIDTH-1:0]    wGEO2_IO__Adr_O_Pointer;
102
wire                                                                             wEXE_2__DataWriteEnable;
103
wire                                                                             wUCODE_RAMWriteEnable;
104
wire [2:0]                                                                RamBusOwner;
105
//Unit intercoanection wires
106
 
107
wire                                                                            wCU2__MicrocodeExecutionDone;
108
wire [`ROM_ADDRESS_WIDTH-1:0]            InitialCodeAddress;
109
wire [`ROM_ADDRESS_WIDTH-1:0]            wInstructionPointer1,wInstructionPointer2;
110
wire [`INSTRUCTION_WIDTH-1:0]    wEncodedInstruction1,wEncodedInstruction2,wIO2_MEM__ExternalInstruction;
111
wire                                                                            wCU2__ExecuteMicroCode;
112
wire  [`ROM_ADDRESS_WIDTH-1:0]   wIO2_MEM__InstructionWriteAddr;
113
wire [95:0]                                                      wMEM_2__EXE_DataRead0, wMEM_2__EXE_DataRead1,wMEM_2__IO_DataRead0, wMEM_2__IO_DataRead1;
114
wire [`DATA_ADDRESS_WIDTH-1:0]   wEXE_2__MEM_DataReadAddress0,wEXE_2__MEM_DataReadAddress1;
115
wire [`DATA_ADDRESS_WIDTH-1:0]   wUCODE_RAMReadAddress0,wUCODE_RAMReadAddress1;
116
 
117
 
118
wire [`WIDTH-1:0]                                        w2IO__AddressOffset;
119
wire [`DATA_ADDRESS_WIDTH-1:0]   w2IO__DataWriteAddress;
120
wire                                                                            w2IO__Store;
121
wire                                                                            w2IO__EnableWBMaster;
122
 
123
wire [`DATA_ADDRESS_WIDTH-1:0]   wIO2_MEM__DataWriteAddress;
124
wire [`DATA_ADDRESS_WIDTH-1:0]   wIO_2_MEM__DataReadAddress0;
125
wire [`DATA_ROW_WIDTH-1:0]               wIO2_MEM__Bus;
126
wire [`WIDTH-1:0]                                        wIO2_MEM__Data;
127
wire [`WIDTH-1:0]                                        wIO2_WBM__Address;
128
wire                                                                            wIO2_MEM__DataWriteEnable;
129
wire                                                                            wIO2__Done;
130
wire                                                                            wCU2_GEO__GeometryFetchEnable;
131
wire                                                                            wIFU2__MicroCodeReturnValue;
132
wire                                                                            wCU2_BCU__ACK;
133
wire                                                                            wGEO2_CU__RequestAABBIU;
134
wire                                                                            wGEO2_CU__RequestBIU;
135
wire                             wGEO2_CU__RequestTCC;
136
wire                                                                            wGEO2_CU__GeometryUnitDone;
137
wire                                                                            wGEO2_CU__Sync;
138
wire                                                                            wEXE2__uCodeDone;
139
wire                                                                            wEXE2_IFU__EXEBusy;
140
wire [`DATA_ADDRESS_WIDTH-1:0]   wEXE2_IDU_DataFordward_LastDestination;
141
wire                                                                            wALU2_EXE__BranchTaken;
142
wire                                                                            wALU2_IFU_BranchNotTaken;
143
wire                                                                            w2IO__SetAddress;
144
wire                                                                            wIDU2_IFU__IDUBusy;
145
//Control Registe wires
146
wire[15:0]                                                               wCR2_ControlRegister;
147
wire                                                                            wCR2_TextureMappingEnabled;
148
wire                             wGEO2_CU__TFFDone;
149
wire                             wCU2_GEO__TriggerTFF;
150
wire                             wIO2_MEM_InstructionWriteEnable;
151
wire                             wCU2_IO__WritePixel;
152
wire                             wGEO2_IO__AddrIsImm;
153
wire[31:0]                       wGEO2_IO__AddressOffset;
154
wire                             wGEO2_IO__EnableWBMaster;
155
wire                             wGEO2_IO__SetAddress;
156
wire[`WIDTH-1:0]                 wGEO2__CurrentPitch,wCU2_GEO_Pitch;
157
wire                             wCU2_GEO__SetPitch,wCU2_GEO__IncPicth;
158
wire wCU2_FlipMemEnabled;
159
wire w2MEM_FlipMemory;
160
 
161
`ifdef DEBUG
162
        wire [`ROM_ADDRESS_WIDTH-1:0] wDEBUG_IDU2_EXE_InstructionPointer;
163
`endif
164
//--------------------------------------------------------
165
 
166
 
167
assign wCR2_TextureMappingEnabled = wCR2_ControlRegister[ `CR_EN_TEXTURE ];
168
wire wCU2_FlipMem;
169
//--------------------------------------------------------
170
//Control Unit Instance
171
        ControlUnit CU
172
        (
173
           .Clock(Clock),
174
                .Reset(Reset),
175
                .oFlipMemEnabled(                   wCU2_FlipMemEnabled            ),
176
                .oFlipMem(                          wCU2_FlipMem                   ),
177
                .iControlRegister(                  wCR2_ControlRegister           ),
178
                .oRamBusOwner(                      RamBusOwner                    ),
179
                .oGFUEnable(                        wCU2_GEO__GeometryFetchEnable  ),
180
                .iTriggerAABBIURequest(             wGEO2_CU__RequestAABBIU        ),
181
                .iTriggerBIURequest(                wGEO2_CU__RequestBIU           ),
182
                .iTriggertTCCRequest(               wGEO2_CU__RequestTCC           ),
183
                .oUCodeEnable(                      wCU2__ExecuteMicroCode         ),
184
                .oCodeInstructioPointer(           InitialCodeAddress             ),
185
                .iUCodeDone(                        wCU2__MicrocodeExecutionDone   ),
186
                .iIODone(                           wIO2__Done                     ),
187
                .oIOWritePixel(                     wCU2_IO__WritePixel            ),
188
                .iUCodeReturnValue(                 wIFU2__MicroCodeReturnValue    ),
189
                .iGEOSync(                          wGEO2_CU__Sync                 ),
190
                .iTFFDone(                          wGEO2_CU__TFFDone              ),
191
                .oTriggerTFF(                       wCU2_GEO__TriggerTFF           ),
192
                .MST_I(                             MST_I                          ),
193
                .oSetCurrentPitch(                  wCU2_GEO__SetPitch             ),
194
                .iGFUDone(                          wGEO2_CU__GeometryUnitDone     ),
195
                .iRenderEnable(                     RENDREN_I                      ),
196
 
197
                `ifdef DEBUG
198
                .iDebug_CoreID( iDebug_CoreID ),
199
                `endif
200
                .oDone(                             DONE_O                         )
201
 
202
        );
203
 
204
 
205
 
206
 
207
//--------------------------------------------------------      
208
 
209
//assign w2MEM_FlipMemory =  (wCU2__ExecuteMicroCode | wCU2_FlipMem ) & wCU2_FlipMemEnabled;
210
assign w2MEM_FlipMemory =  wCU2_FlipMem  & wCU2_FlipMemEnabled;
211
MemoryUnit MEM
212
(
213
.Clock(Clock),
214
.Reset(Reset),
215
 
216
.iFlipMemory( w2MEM_FlipMemory ),
217
 
218
//Data Bus to/from EXE
219
.iDataReadAddress1_EXE(       wEXE_2__MEM_DataReadAddress0        ),
220
.iDataReadAddress2_EXE(       wEXE_2__MEM_DataReadAddress1        ),
221
.oData1_EXE(                  wMEM_2__EXE_DataRead0               ),
222
.oData2_EXE(                  wMEM_2__EXE_DataRead1               ),
223
.iDataWriteEnable_EXE(        wEXE_2__DataWriteEnable          ),
224
.iDataWriteAddress_EXE(       wEXE_2__MEM_wDataWriteAddress        ),
225
.iData_EXE(                   wEXE_2__MEM_WriteData          ),
226
 
227
//Data Bus to/from IO
228
 
229
.iDataReadAddress1_IO(       wIO_2_MEM__DataReadAddress0        ),
230
.iDataReadAddress2_IO(       wIO_2_MEM__DataReadAddress1        ),
231
.oData1_IO(                  wMEM_2__IO_DataRead0               ),
232
.oData2_IO(                  wMEM_2__IO_DataRead1               ),
233
.iDataWriteEnable_IO(        wIO2_MEM__DataWriteEnable          ),
234
.iDataWriteAddress_IO(       wIO2_MEM__DataWriteAddress        ),
235
.iData_IO(                   wIO2_MEM__Bus          ),
236
 
237
 
238
//Instruction Bus
239
.iInstructionReadAddress1(  wInstructionPointer1             ),
240
.iInstructionReadAddress2(  wInstructionPointer2             ),
241
.oInstruction1(             wEncodedInstruction1             ),
242
.oInstruction2(             wEncodedInstruction2             ),
243
.iInstructionWriteEnable(  wIO2_MEM_InstructionWriteEnable ),
244
.iInstructionWriteAddress( wIO2_MEM__InstructionWriteAddr  ),
245
.iInstruction(             wIO2_MEM__ExternalInstruction   ),
246
.iControlRegister(         CREG_I                          ),
247
.oControlRegister(         wCR2_ControlRegister            )
248
 
249
);
250
 
251
////--------------------------------------------------------
252
 
253
 
254
ExecutionUnit EXE
255
(
256
 
257
.Clock( Clock),
258
.Reset( Reset ),
259
.iInitialCodeAddress(    InitialCodeAddress     ),
260
.iInstruction1(          wEncodedInstruction1      ),
261
.iInstruction2(          wEncodedInstruction2      ),
262
.oInstructionPointer1(   wInstructionPointer1    ),
263
.oInstructionPointer2(   wInstructionPointer2    ),
264
.iDataRead0(             wMEM_2__EXE_DataRead0             ),
265
.iDataRead1(             wMEM_2__EXE_DataRead1             ),
266
.iTrigger(               wCU2__ExecuteMicroCode ),
267
.oDataReadAddress0( wEXE_2__MEM_DataReadAddress0 ),
268
.oDataReadAddress1( wEXE_2__MEM_DataReadAddress1 ),
269
.oDataWriteEnable(  wEXE_2__DataWriteEnable  ),
270
.oDataWriteAddress( wEXE_2__MEM_wDataWriteAddress      ),
271
.oDataBus(          wEXE_2__MEM_WriteData          ),
272
.oReturnCode(       wIFU2__MicroCodeReturnValue ),
273
 
274
`ifdef DEBUG
275
.iDebug_CoreID( iDebug_CoreID ),
276
`endif
277
.oDone(             wCU2__MicrocodeExecutionDone )
278
 
279
);
280
 
281
////--------------------------------------------------------
282
wire wGEO2__RequestingTextures;
283
wire w2IO_WriteBack_Set;
284
 
285
GeometryUnit GEO
286
(
287
                .Clock( Clock ),
288
                .Reset( Reset ),
289 82 diegovalve
                .iEnable(                     wCU2_GEO__GeometryFetchEnable       ),
290
                .iIOBusy( wIO_Busy ),
291 76 diegovalve
                .iTexturingEnable(            wCR2_TextureMappingEnabled          ),
292
                //Wires from IO
293
                .iData_WBM(                                             wIO2_MEM__Data ),
294
                .iDataReady_WBM(                                        wIO2__Done ),
295
                //Wires to WBM
296
                .oAddressWBM_Imm(                               wGEO2_IO__AddressOffset                                 ),
297
                .oAddressWBM_fromMEM(         wGEO2_IO__Adr_O_Pointer             ),
298
                .oAddressWBM_IsImm(           wGEO2_IO__AddrIsImm                 ),
299
                .oEnable_WBM(                                           wGEO2_IO__EnableWBMaster                                ),
300
                .oSetAddressWBM(                                        wGEO2_IO__SetAddress                                            ),
301
                .oSetIOWriteBackAddr(         w2IO_WriteBack_Set                  ),
302
                //Wires to CU
303
                .oRequest_AABBIU(             wGEO2_CU__RequestAABBIU                ),
304
                .oRequest_BIU(                wGEO2_CU__RequestBIU                   ),
305
                .oRequest_TCC(                wGEO2_CU__RequestTCC                   ),
306
                .oTFFDone(                    wGEO2_CU__TFFDone                      ),
307
                //Wires to RAM-Bus MUX  
308 82 diegovalve
                .oRAMWriteAddress(                              w2IO__DataWriteAddress                                     ),
309
                .oRAMWriteEnable(                               w2IO__Store                            ),
310 76 diegovalve
                //Wires from Execution Unit
311
                .iMicrocodeExecutionDone(               wCU2__MicrocodeExecutionDone                            ),
312
                .iMicroCodeReturnValue(                 wIFU2__MicroCodeReturnValue                             ),
313
                .oSync(                                                         wGEO2_CU__Sync                                                                  ),
314
                .iTrigger_TFF(                wCU2_GEO__TriggerTFF                   ),
315
                .iBIUHit(                     wIFU2__MicroCodeReturnValue            ),
316 82 diegovalve
                .oRequestingTextures(         wGEO2__RequestingTextures              ),
317
                `ifdef DEBUG
318
                .iDebug_CoreID(               iDebug_CoreID                          ),
319
                `endif
320 76 diegovalve
                .oDone(                                                         wGEO2_CU__GeometryUnitDone                                      )
321
);
322
 
323
 
324
assign TGA_O = (wGEO2__RequestingTextures) ? 2'b1: 2'b0;
325
//---------------------------------------------------------------------------------------------------
326
wire[`DATA_ADDRESS_WIDTH-1:0] wIO_2_MEM__DataReadAddress1;
327
assign wEXE_2__MEM_DataReadAddress1 = (wCU2_IO__WritePixel == 0) ?  wUCODE_RAMReadAddress1 : wIO_2_MEM__DataReadAddress1;
328
assign w2IO__EnableWBMaster = (wCU2_IO__WritePixel == 0 ) ? wGEO2_IO__EnableWBMaster : wCU2_IO__WritePixel;
329
assign w2IO__AddrIsImm       = (wCU2_IO__WritePixel == 0 ) ? wGEO2_IO__AddrIsImm       : 1'b0;
330
assign w2IO__AddressOffset   = (wCU2_IO__WritePixel == 0 ) ? wGEO2_IO__AddressOffset   : 32'b0;
331
assign w2IO__Adr_O_Pointer      = (wCU2_IO__WritePixel == 0 ) ? wGEO2_IO__Adr_O_Pointer : `OREG_ADDR_O;
332
//assign w2IO__Adr_O_Pointer      = (wCU2_IO__WritePixel == 0 ) ? wGEO2_IO__Adr_O_Pointer : `CREG_PIXEL_2D_INITIAL_POSITION; 
333
 
334
wire w2IO_MasterCycleType;
335
assign w2IO_MasterCycleType = (wCU2_IO__WritePixel) ? `WB_SIMPLE_WRITE_CYCLE : `WB_SIMPLE_READ_CYCLE;
336
 
337
 
338
 
339
assign w2IO__SetAddress = (wCU2_IO__WritePixel == 0 )? wGEO2_IO__SetAddress : wCU2_GEO__SetPitch;
340
 
341
 
342
IO_Unit IO
343
(
344
 .Clock(               Clock                            ),
345
 .Reset(               Reset                            ),
346
 .iEnable(            w2IO__EnableWBMaster              ),
347
 .iBusCyc_Type(         w2IO_MasterCycleType            ),
348
 
349
 .iStore(              w2IO__Store                      ),
350
 .iAdr_DataWriteBack(    w2IO__DataWriteAddress         ),
351
 .iAdr_O_Set(      w2IO__SetAddress                     ),
352
 .iAdr_O_Imm(       w2IO__AddressOffset                 ),
353
 .iAdr_O_Type(      w2IO__AddrIsImm                     ),
354
 .iAdr_O_Pointer(  w2IO__Adr_O_Pointer                  ),
355
 .iReadDataBus(        wMEM_2__IO_DataRead0                       ),
356
 .iReadDataBus2(        wMEM_2__IO_DataRead1                       ),
357
 .iDat_O_Pointer(     `OREG_PIXEL_COLOR                 ),
358
 
359
 
360
 .oDataReadAddress(    wIO_2_MEM__DataReadAddress0      ),
361
 .oDataReadAddress2(   wIO_2_MEM__DataReadAddress1       ),
362
 .oDataWriteAddress(   wIO2_MEM__DataWriteAddress    ),
363
 .oDataBus(               wIO2_MEM__Bus                 ),
364
 .oInstructionBus(     wIO2_MEM__ExternalInstruction    ),
365
 
366
 .oDataWriteEnable(         wIO2_MEM__DataWriteEnable    ),
367
 .oData(                    wIO2_MEM__Data                       ),
368
 .oInstructionWriteEnable(  wIO2_MEM_InstructionWriteEnable ),
369
 .oInstructionWriteAddress( wIO2_MEM__InstructionWriteAddr ),
370
 .iWriteBack_Set( w2IO_WriteBack_Set ),
371 82 diegovalve
 .oBusy(                      wIO_Busy                  ),
372 76 diegovalve
 .oDone(               wIO2__Done                       ),
373
 .MST_I( MST_I ),
374
  //Wish Bone Interface
375
.DAT_I( DAT_I ),
376
.DAT_O( DAT_O ),
377
.ACK_I( ACK_I & GNT_I ),
378
.ACK_O( ACK_O ),
379
.ADR_O( ADR_O ),
380
.ADR_I( ADR_I ),
381
.WE_O(  WE_O  ),
382
.WE_I(  WE_I  ),
383
.STB_O( STB_O ),
384
.STB_I( STB_I ),
385
.CYC_O( CYC_O ),
386
.TGA_I( TGA_I ),
387
.CYC_I( CYC_I ),
388
.GNT_I( GNT_I ),
389
.TGC_O( TGC_O )
390
 
391
 
392
);
393
//---------------------------------------------------------------------------------------------------
394
endmodule

powered by: WebSVN 2.1.0

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