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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [testbench/] [TestBench_verilog.v] - Blame information for rev 186

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

Line No. Rev Author Line
1 171 diegovalve
 
2
 
3
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22
 
23
 
24
/*******************************************************************************
25
Module Description:
26
 
27
This is the Main test bench of the GPU. It simulates the behavior of
28
an external control unit or CPU that sends configuration information into DUT.
29
It also implements a second processs that simulates a Wishbone slave that sends
30
data from an external memory. These blocks are just behavioral CTE and therefore
31
are not meant to be synthethized.
32
 
33
*******************************************************************************/
34
 
35
 
36
 
37
`timescale 1ns / 1ps
38
`include "aDefinitions.v"
39
`define RESOLUTION_WIDTH        (rSceneParameters[13] >> `SCALE)
40
`define RESOLUTION_HEIGHT        (rSceneParameters[14] >> `SCALE)
41 179 diegovalve
`define DELTA_ROW          (32'h1 << `SCALE)
42 171 diegovalve
`define DELTA_COL          (32'h1 << `SCALE)
43
`define TEXTURE_BUFFER_SIZE       (256*256*3)
44
`define MAX_WIDTH          200
45
`define MAX_SCREENBUFFER        (`MAX_WIDTH*`MAX_WIDTH*3)
46
module TestBench_Theia;
47
 
48
 
49
 //------------------------------------------------------------------------
50
 //**WARNING: Declare all of your varaibles at the begining
51
 //of the file. I hve noticed that sometimes the verilog
52
 //simulator allows you to use some regs even if they have not been 
53
 //previously declared, leadeing to crahses or unexpected behavior
54
 // Inputs
55
 reg Clock;
56
 reg Reset;
57
 wire [`WB_WIDTH-1:0]   DAT_O;
58
 reg          ACK_O;
59
 wire        ACK_I;
60
 wire [`WB_WIDTH-1:0]   ADR_I,ADR_O;
61
 wire         WE_I,STB_I;
62
 wire         CYC_O,WE_O,TGC_O,STB_O;
63
 wire [1:0]       TGA_O;
64
 wire [1:0]       TGA_I;
65
 reg [`WB_WIDTH-1:0]    TMADR_O,TMDAT_O;
66
 reg [`MAX_TMEM_BANKS-1:0]  TMSEL_O;
67
 reg         TMWE_O;
68
 reg [31:0]       rControlRegister[2:0];
69
 integer          file, log;
70
 reg [31:0]       rSceneParameters[120:0];
71
 reg [31:0]       rVertexBuffer[7000:0];
72
 reg [31:0]       rInstructionBuffer[512:0];
73
 reg [31:0]       rTextures[`TEXTURE_BUFFER_SIZE:0];  //Lets asume we use 256*256 textures
74
 reg [7:0]        rScreen[`MAX_SCREENBUFFER-1:0];
75
 
76
 wire         wDone;
77
 wire [`MAX_CORES-1:0]   RENDREN_O;
78
 reg [`MAX_CORE_BITS-1:0]   wOMEMBankSelect;
79
 reg [`WB_WIDTH-1:0]    wOMEMReadAddr;  //Output adress (relative to current bank)
80
 wire [`WB_WIDTH-1:0]       wOMEMData;   //Output data bus (Wishbone)
81
 reg        rHostEnable;
82
 integer       k,out2;
83
 wire GRDY_I;
84
 wire GACK_O;
85
 wire STDONE_O;
86
 wire wGPUCommitedResults;
87
 wire wHostDataAvailable;
88
 
89
 
90
wire[`WB_WIDTH-1:0]               wHostReadAddress;
91
wire[`WB_WIDTH-1:0]               wMemorySize;
92
wire[1:0]                         wMemSelect;
93
 
94
MUXFULLPARALELL_2SEL_GENERIC # ( `WB_WIDTH ) MUX2
95
 (
96
.Sel( wMemSelect ),
97
.I1(  rInstructionBuffer[0] ),
98
.I2(  rSceneParameters[0]   ),
99
.I3(  rVertexBuffer[0]      ),
100
.I4(0),
101
.O1(wMemorySize)
102
 );
103
 
104
 
105
 //---------------------------------------------
106
 top Top
107
(
108
.Clock( Clock ),
109
.Reset( Reset ),
110
.iHostEnable(      rHostEnable ),
111
.oHostReadAddress( wHostReadAddress),
112
.iMemorySize(      wMemorySize     ),
113
.oMemSelect(       wMemSelect      ),
114
.iInstruction(     rInstructionBuffer[wHostReadAddress] ),
115
.iParameter(       rSceneParameters[wHostReadAddress]   ),
116
.iVertex(          rVertexBuffer[wHostReadAddress]      ),
117
.iControlRegister( rControlRegister[0]                  ),
118
.iPrimitiveCount(  (rVertexBuffer[6]+1) *7              ),
119
.iTMEMAdr( TMADR_O ),
120
.iTMEMData( TMDAT_O ),
121
.iTMEM_WE( TMWE_O ),
122
.iTMEM_Sel( TMSEL_O ),
123
.iOMEMBankSelect(  wOMEMBankSelect ),
124
.iOMEMReadAddress( wOMEMReadAddr ),
125
.oOMEMData( wOMEMData ),
126 179 diegovalve
 
127
.iWidth(`RESOLUTION_WIDTH),
128
.iHeight(`RESOLUTION_HEIGHT),
129 171 diegovalve
.oDone( wDone )
130
 
131
 
132
);
133
 //---------------------------------------------
134
 //generate the clock signal here
135
 always begin
136
  #`CLOCK_CYCLE  Clock =  ! Clock;
137
 
138
 end
139
 //---------------------------------------------
140
 
141
 
142
//-------------------------------------------------------------------------------------
143
/*
144
This makes sure the simulation actually writes the results to the PPM image file
145
once all the cores are done executing
146
*/
147
`define PARTITION_SIZE `RESOLUTION_HEIGHT/`MAX_CORES
148
integer i,j,kk;
149
reg [31:0] R;
150
always @ ( * )
151
begin
152
 
153
 
154
if (wDone == 1'b1)
155
begin
156
 
157
 $display("Partition Size = %d",`PARTITION_SIZE);
158
 for (kk = 0; kk < `MAX_CORES; kk = kk+1)
159
   begin
160
   wOMEMBankSelect = kk;
161
    $display("wOMEMBankSelect = %d\n",wOMEMBankSelect);
162
    for (j=0; j < `PARTITION_SIZE; j=j+1)
163
    begin
164
 
165
     for (i = 0; i < `RESOLUTION_HEIGHT*3; i = i +1)
166
     begin
167
     wOMEMReadAddr = i+j*`RESOLUTION_WIDTH*3;
168
     #`CLOCK_PERIOD;
169
     #1;
170
     R = ((wOMEMData >> (`SCALE-8)) > 255) ? 255 : (wOMEMData >>  (`SCALE-8));
171
     $fwrite(out2,"%d " , R );
172
 
173
      if ((i %3) == 0)
174
        $fwrite(out2,"\n# %d %d\n",i/3,j);
175
 
176
     end
177
    end
178
   end
179
 
180
 
181
 
182
   $fclose(out2);
183
   $fwrite(log, "Simulation end time : %dns\n",$time);
184
   $fclose(log);
185
 
186
 
187
   $stop();
188
 
189
 
190
end
191
end
192
//-------------------------------------------------------------------------------------
193
 
194
reg [15:0] rTimeOut;
195
 
196
 // `define MAX_INSTRUCTIONS 2
197
 
198
 initial begin
199
  // Initialize Inputs
200
 
201
 
202
  Clock      = 0;
203
  Reset      = 0;
204
  rTimeOut             = 0;
205
  rHostEnable    = 0;
206
  //Read Config register values
207
  $write("Loading control register.... ");
208
  $readmemh("Creg.mem",rControlRegister);
209
  $display("Done");
210
 
211
 
212
 
213
  //Read configuration Data
214
  $write("Loading scene parameters.... ");
215
  $readmemh("Params.mem", rSceneParameters );
216
  $display("Done");
217
 
218
 
219
  //Read Scene Data
220
  $write("Loading scene geometry.... ");
221
  $readmemh("Vertex.mem",rVertexBuffer);
222
  $display("Done");
223
 
224
  $display("Number of primitives(%d): %d",rVertexBuffer[6],(rVertexBuffer[6]+1) *7);
225
 
226
 
227
  //Read Texture Data
228
  $write("Loading scene texture.... ");
229
  $readmemh("Textures.mem",rTextures);
230
  $display("Done");
231
 
232
 
233
  //Read instruction data
234
  $write("Loading code allocation table and user shaders.... ");
235
  $readmemh("Instructions.mem",rInstructionBuffer);
236
  $display("Done");
237
 
238
  $display("Control Register : %b",rControlRegister[0]);
239
  $display("Resolution       : %d X %d",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
240
 
241 186 diegovalve
 
242 171 diegovalve
  //Open output file
243
  out2 = $fopen("Output.ppm");
244
 
245
  $fwrite(out2,"P3\n");
246
  $fwrite(out2,"#This file was generated by Theia's RTL simulation\n");
247
  $fwrite(out2,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
248
  $fwrite(out2,"255\n");
249
 
250
  #10
251
  Reset = 1;
252
 
253
 
254
  // Wait 100 ns for global reset to finish
255
  TMWE_O = 1;
256
  #100  Reset = 0;
257
  TMWE_O = 1;
258
 
259
  $display("Intilializing TMEM @ %dns",$time);
260
  //starts in 2 to skip Width and Height
261
  for (k = 0;k < `TEXTURE_BUFFER_SIZE; k = k + 1)
262
  begin
263
 
264
   TMADR_O <= (k >> (`MAX_CORE_BITS));
265
   TMSEL_O <= (k & (`MAX_TMEM_BANKS-1));  //X mod 2^n == X & (2^n - 1)
266
   TMDAT_O <= rTextures[k];
267
   #10;
268
   if ((k % (256*3)) == 0)
269
   begin
270
    $write("|");
271
    $fflush;
272
   end
273
  end
274
  $display("\nDone Intilializing TMEM @ %dns",$time);
275
  TMWE_O = 0;
276
  rHostEnable = 1;
277
 
278 186 diegovalve
  log  = $fopen("Simulation.log");
279
  $fwrite(log, "Simulation start time : %dns\n",$time);
280
  $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
281
  $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
282
 
283 171 diegovalve
  //Start dumping VCD
284
  $display("-I- Starting VCD Dump\n");
285
 // $dumpfile("TestBench_Theia.vcd");
286
 // $dumpvars(0,TestBench_Theia);
287
 
288
 end
289
 
290
 
291 186 diegovalve
endmodule

powered by: WebSVN 2.1.0

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