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

Subversion Repositories jart

[/] [jart/] [trunk/] [BLRT/] [powerGrid.vhd] - Blame information for rev 36

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

Line No. Rev Author Line
1 16 jguarin200
-- Author : Julian Andres Guarin Reyes.
2
-- Project : JART, Just Another Ray Tracer.
3
-- email : jguarin2002 at gmail.com, j.guarin at javeriana.edu.co
4
 
5
-- This code was entirely written by Julian Andres Guarin Reyes.
6
-- The following code is licensed under GNU Public License
7
-- http://www.gnu.org/licenses/gpl-3.0.txt.
8
 
9
 -- This file is part of JART (Just Another Ray Tracer).
10
 
11
    -- JART (Just Another Ray Tracer) is free software: you can redistribute it and/or modify
12
    -- it under the terms of the GNU General Public License as published by
13
    -- the Free Software Foundation, either version 3 of the License, or
14
    -- (at your option) any later version.
15
 
16
    -- JART (Just Another Ray Tracer) is distributed in the hope that it will be useful,
17
    -- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    -- GNU General Public License for more details.
20
 
21
    -- You should have received a copy of the GNU General Public License
22
    -- along with JART (Just Another Ray Tracer).  If not, see <http://www.gnu.org/licenses/>.
23
 
24
-- 16X50M Intersection Tests    
25
 
26
library ieee;
27
use ieee.std_logic_1164.all;
28
 
29
package powerGrid is
30
 
31 33 jguarin200
        --A one stage pipe (1 Clk) a+b+c with w width bits in input as well as output.
32
        --As a fixed signed addtion we have:
33
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
34
        -- A(15,20)*A(15,20) = A(15,20). (This component format)
35
 
36 22 jguarin200
        component p1ax
37 33 jguarin200
                generic (
38
                -- The width of the operands and result.
39
                W               : integer := 36 );
40
                port    (
41
                -- The usual control signals.
42
                clk             :        in std_logic;
43
                rst             :        in std_logic;
44
                enable          :        in std_logic;
45
 
46
                -- Operand A.
47
                dataa           :        in std_logic_vector(W-1 downto 0);
48
                -- Operand B.
49
                datab           :        in std_logic_vector(W-1 downto 0);
50
                -- Operand C
51
                datac           :        in std_logic_vector(W-1 downto 0);
52
                -- Result.
53
                result          :        out std_logic_vector(W-1 downto 0)
54 22 jguarin200
                );
55
        end component;
56
 
57
        -- A 1 stage pipe 18x18 multiplier. On Cycle III devices is a M-R (Multiplier, Register). (Should be generated using a synthesis tool....).
58 33 jguarin200
        -- As a fixed signed multiplication we have :
59
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
60
        -- A(7,10)*A(7,10) = A(15,20). (This component format)
61
 
62 22 jguarin200
        component p1m18
63
                port    (
64 33 jguarin200
                -- Asynchronous clear signal.
65
                aclr            : in std_logic ;
66
                -- The usual control signals.
67
                clken           : in std_logic ;
68
                clock           : in std_logic ;
69
 
70
                -- Factor A.
71
                dataa           : in std_logic_vector (17 downto 0);
72
                -- Factor B.
73
                datab           : in std_logic_vector (17 downto 0);
74
                -- Product.
75
                result          : out std_logic_vector (35 downto 0)
76 22 jguarin200
                );
77
        end component;
78
 
79 33 jguarin200
        -- Signed "less than". dataa < datab
80 16 jguarin200
        component sl32
81
                port    (
82 33 jguarin200
 
83
                dataa   : in std_logic_vector (31 downto 0);
84
                datab   : in std_logic_vector (31 downto 0);
85
                AlB             : out std_logic
86
 
87 16 jguarin200
                );
88
                end component;
89
 
90 33 jguarin200
        -- Signed "greater than". dataa >= datab.
91 16 jguarin200
        component sge32
92
                port    (
93 33 jguarin200
 
94
                dataa   : in std_logic_vector (31 downto 0);
95
                datab   : in std_logic_vector (31 downto 0);
96
                AgeB    : out std_logic
97
 
98 16 jguarin200
                );
99
                end component;
100
 
101
 
102 22 jguarin200
        -- Dot Product Calculation Cell. 
103
        -- A 4 side cell along with an upper side. 
104
        -- V input flows through V output using a data flipflop, so turning V output in the next cell on the next row V Input. V input also flows upwards into the dotproduct 3 stage pipeline. 
105
        -- D input flows through D output using a data flipflop, so turning D output in the next column cell. D input also flows upwards into the dotproduct 3 stage. 
106 16 jguarin200
        component dotCell
107 33 jguarin200
                generic (
108
                -- Actual Level Width
109
                levelW  : integer := 18;
110
                -- Next Level Width
111
                nLevelW : integer := 32);
112
 
113 16 jguarin200
                port    (
114 33 jguarin200
                --The usual control signals
115
                clk                     : in std_logic;
116
                rst                     : in std_logic;
117 16 jguarin200
 
118 33 jguarin200
                -- This bit controls when the sphere center goes to the next row.
119
                nxtSphere       : in std_logic;
120
                -- This bit controls when the ray goes to the next column.
121
                nxtRay          : in std_logic;
122 22 jguarin200
 
123 33 jguarin200
                -- First Side.
124
                vxInput         : in std_logic_vector(levelW-1 downto 0);
125
                vyInput         : in std_logic_vector(levelW-1 downto 0);
126
                vzInput         : in std_logic_vector(levelW-1 downto 0);
127 16 jguarin200
 
128 33 jguarin200
                -- Second Side (Opposite to the first one)
129
                vxOutput        : out std_logic_vector(levelW-1 downto 0);
130
                vyOutput        : out std_logic_vector(levelW-1 downto 0);
131
                vzOutput        : out std_logic_vector(levelW-1 downto 0);
132 16 jguarin200
 
133 33 jguarin200
                -- Third Side (Perpendicular to the first and second ones)
134
                dxInput         : in std_logic_vector(levelW-1 downto 0);
135
                dyInput         : in std_logic_vector(levelW-1 downto 0);
136
                dzInput         : in std_logic_vector(levelW-1 downto 0);
137 16 jguarin200
 
138 33 jguarin200
                --Fourth Side (Opposite to the third one)
139
                dxOutput        : in std_logic_vector(levelW-1 downto 0);
140
                dyOutput        : in std_logic_vector(levelW-1 downto 0);
141
                dzOutput        : in std_logic_vector(levelW-1 downto 0);
142 16 jguarin200
 
143 33 jguarin200
                --Fifth Side (Going to the floor right upstairs!)
144
                vdOutput        : out std_logic_vector(nLevelW-1 downto 0) -- Dot product.
145 16 jguarin200
 
146 22 jguarin200
                );
147 16 jguarin200
        end component;
148
 
149
        -- K discriminant comparison.
150 33 jguarin200
        -- The vdinput value is the calculation of the ray and the column's sphere dot product. This value should be compared to a sphere constant in order to find out whether the ray intersects
151
        -- or not the sphere. If vdinput is grather or equal than kinput there's an intersection or else when vdinput is less than kinput. If there's an intersection the block sets vdinput at vdoutput,
152
        -- whenever there's no intersection the output is asserted with the maximum positive distance in 32 bits : 0x7fffffff.
153 16 jguarin200
        component kComparisonCell
154
                generic (       W               : integer := 32;
155
                                );
156
                port    (
157 33 jguarin200
                clk                     : in std_logic;
158
                rst                     : in std_logic;
159 16 jguarin200
 
160 33 jguarin200
                -- Controls when the sphere goes to the next Grid.
161
                nxtSphere       : in std_logic;
162
                -- Enables / Disables the upwarding flow.
163
                pipeOn          : in std_logic;
164
                -- Sphere's Center vector over ray vector projection.
165
                vdinput : in std_logic_vector (W-1 downto 0);
166
                -- Incoming sphere's K.
167
                kinput  : in std_logic_vector (W-1 downto 0);
168
                -- Signal to connect the sphere's K to the next grid.
169
                koutput : out std_logic_vector (W-1 downto 0);
170
                -- Selected dot product  : The value of this output depends upon whether or not ray sphere intersection.                        
171
                vdoutput: out std_logic_vector (W-1 downto 0)
172 16 jguarin200
                );
173 22 jguarin200
        end component;
174 33 jguarin200
        -- Minimun distance Comparison.
175
        -- The reference value, refvd, is the ray minimal intersection distance calculated in the moment of the comparison. 
176
        -- The column value, colvd, is the column sphere and ray intersection distance (if any or else the maximum distance is asserted).
177
 
178
 
179
        component dComparisonCell
180
                generic (
181
                -- V.D, minDistance and selectD Width 
182
                W               : integer := 32;
183
                -- Column Sphere ID width. 1 = 2 columns max, 2= 4 colums max... and so on.
184
                idColW  : integer := 2;
185
                -- Column Id
186
                idCol   : integer := 0
187
                );
188
                port    (
189
                -- The usual control signals.           
190
                clk             : in std_logic;
191
                rst             : in std_logic;
192
                -- This is the reference column identification input.
193
                cIdd    : in    std_logic_vector (idColW - 1 downto 0);
194
                -- This is the result column identification output.
195
                cIdq    : out   std_logic_vector (idColW - 1 downto 0);
196
                -- This is the reference projection incoming from the previous cell.
197
                refvd   : in    std_logic_vector (W - 1 downto 0);
198
                -- This is the sphere position over the ray traced vector projection.
199
                colvd   : in    std_logic_vector (W - 1 downto 0);
200
                -- This is the smallest value between refvd and colvd.
201
                selvd   : out   std_logic_vector (W - 1 downto 0)
202
                );
203
        end component;
204
 
205
        component floor0Row
206
                generic (
207
                -- Floor Level Width (V.D width)
208
                nlw : integer := 32;
209
                -- Vector input Width           
210
                viw : integer := 18;
211
                -- Number of Colums
212
                col     : integer := 4;
213
        );
214
        port (
215
                -- The usual control signals. nxtRay should be 0 whenever I want to stop the entire machine.
216
                clk, rst, nxtRay : in std_logic;
217 16 jguarin200
 
218 33 jguarin200
                -- Clk, Rst, the usual control signals.
219
                -- enabled, the machine is running when this input is set.
220
                -- enabled, all the counters begin again.
221
                nxtSphere : in std_logic_vector (col-1 downto 0);
222
 
223
 
224
                -- Input Values. 
225
                -- The ray input vector.
226
                iRayx: in std_logic_vector (viw - 1 downto 0);
227
                iRayy: in std_logic_vector (viw - 1 downto 0);
228
                iRayz: in std_logic_vector (viw - 1 downto 0);
229
 
230
                -- The spheres x position (sphere centers) input vectors.
231
                iSphrCenterx: in std_logic_vector (col*viw - 1 downto 0);
232
                -- The spheres y position (sphere centers) input vectors.
233
                iSphrCentery: in std_logic_vector (col*viw - 1 downto 0);
234
                -- The spheres z position (sphere centers) input vectors.
235
                iSphrCenterz: in std_logic_vector (col*viw - 1 downto 0);
236
                -- The spheres x position (sphere centers) output vectors.
237
                oSphrCenterx: out std_logic_vector (col*viw - 1 downto 0);
238
                -- The spheres y positions (sphere centes) output vectors.
239
                oSphrCentery: out std_logic_vector (col*viw - 1 downto 0);
240
                -- The spheres z positions (sphere centers) output vectors.             
241
                oSphrCenterz: out std_logic_vector (col*viw - 1 downto 0);
242
 
243
                -- Output Values
244
                -- The ray output vector.
245
                oRayx: out std_logic_vector (viw - 1 downto 0);
246
                oRayy: out std_logic_vector (viw - 1 downto 0);
247
                oRayz: out std_logic_vector (viw - 1 downto 0);
248
 
249
                -- The dot product result from each dot prod cell.
250
                vdOutput : out std_logic_vector (nlw*col - 1 downto 0)
251
                );
252
        end component;
253
 
254
        -- In this level the V.D results from floor 0 are compared whether they are greater or equal than column's sphere K constants, in order to find if there's an intersection per column or not.
255
        -- When any comparison is true, meaning VD value greater or equal than K, the outgoing value to floor2 level is the same VD, if not the outgoing value is 0x7fffffff (the maximum)
256
        -- distance value.
257
 
258
        component floor1Row
259
        generic (
260
 
261
                -- Vector input Width   
262
                viw : integer := 32;
263
                -- Number of Colums
264
                col     : integer := 4;
265
        );
266
        port (
267
 
268
                -- Input Control Signals, pipe on is one when raysr going on. 
269
                clk, rst        : in std_logic;
270
                pipeOn          : in std_logic;
271
 
272
                -- Clk, Rst, the usual control signals.
273
                nxtSphere       : in std_logic_vector (col-1 downto 0);
274
 
275
                -- VD Input / Output.
276
                vdInput : in std_logic_vector (viw*col-1 downto 0);
277
                vdOutput: out std_logic_vector (viw*col-1 downto 0);
278
 
279
                -- K Input / Output.
280
                kInput  : in std_logic_vector (viw*col - 1 downto 0);
281
                kOutput : out std_logic_vector (viw*col - 1 downto 0)
282
        );
283
        end component;
284
 
285
        -- This level takes the -on the moment smalles distance-- value per ray in the extreme left, and starts making comparisons from left to right, one comparison each clock and so on, searching for the smallest V.D value in the row incomung from the floor1 level. When the ray has finished crossing throguh all the spheres in the scene, the row extreme right value will be the smallest V.D found along with an ID of the sphere intersected. This is the goal of the intersection architecture : to find out which is the closest sphere intersected by a particular ray. 
286
 
287
        component floor2Row
288
        generic (
289
                -- Vector input Width
290
                viw : integer := 32;
291
                -- ID Column width
292
                idColW : integer := 2;
293
                -- Number of Colums
294
                col     : integer := 4;
295
        );
296
        port (
297
                -- Input Control Signal
298
                -- Clk, Rst, the usual control signals.
299
                clk, rst, pipeOn: in std_logic;
300
 
301
                -- Input Values
302
                -- Reference VD, the "at the moment" smallest VD sphere ray projection value.
303
                refvd   : in std_logic_vector (viw-1 downto 0);
304
 
305
                -- The smallest VD, value found.
306
                selvd   : out std_logic_vector (viw-1 downto 0);
307
 
308
                -- The column's sphere ray projection value.
309
                colvd   : in std_logic_vector (viw*col-1 downto 0);
310
                -- The smallest VD projection value column id.
311
                colid   : out std_logic_vector (idColW-1 downto 0);
312
                -- The intersection signal (1 on intersection else 0).
313
                inter   : out std_logic
314
        );
315
        end component;
316
 
317
        component rayxsphereGrid
318
        generic (
319
                -- Width of Column identificator.
320
                IDW     : integer := 2;
321
                -- Number of Columns.
322
                C       : integer := 4;
323
                -- Input rays width.
324
                W0      : integer := 18;
325
                -- Dot products and spheres constant width
326
                W1      : integer := 32;
327
 
328
                );
329
        port (
330
                -- The usual control signals.
331
                clk,rst         : in std_logic;
332
 
333
                -- Grid, rays and sphere flow through control signals.
334
                pipeOn          : in std_logic;
335
                nxtSphere       : in std_logic_vector (C-1 downto 0);
336
 
337
                -- R-F0
338
                -- Input Values. 
339
                -- The ray input vector.
340
                iRayx: in std_logic_vector (W0 - 1 downto 0);
341
                iRayy: in std_logic_vector (W0 - 1 downto 0);
342
                iRayz: in std_logic_vector (W0 - 1 downto 0);
343
                -- The spheres x position (sphere centers) input vectors.
344
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
345
                -- The spheres y position (sphere centers) input vectors.
346
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
347
                -- The spheres z position (sphere centers) input vectors.
348
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
349
                -- The spheres x position (sphere centers) output vectors.
350
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
351
                -- The spheres y positions (sphere centes) output vectors.
352
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
353
                -- The spheres z positions (sphere centers) output vectors.             
354
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
355
                -- Output Values
356
                -- The ray output vector.
357
                oRayx: out std_logic_vector (W0 - 1 downto 0);
358
                oRayy: out std_logic_vector (W0 - 1 downto 0);
359
                oRayz: out std_logic_vector (W0 - 1 downto 0);
360
 
361
                -- R-F1
362
                -- K Input / Output.
363
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
364
                kOutput : out std_logic_vector (C*W1 - 1 downto 0)
365
 
366
                --R-F2
367
                -- Input Values
368
                refvd   : in std_logic_vector (W1-1 downto 0);
369
                selvd   : out std_logic_vector (W1-1 downto 0);
370
                colid   : out std_logic_vector (IDW-1 downto 0);
371
                inter   : out std_logic
372
                );
373
        end component;
374
        component gridCube
375
        generic (
376
                -- Depth
377
                D       : integer := 4;
378
                -- ID width.
379
                IDW     : integer := 2;
380
                -- Number of Columns.
381
                C       : integer := 4;
382
                -- Input rays width.
383
                W0      : integer := 18;
384
                -- Dot products and spheres constant width
385
                W1      : integer := 32;        IDW     : integer := 2;
386
 
387
                );
388
        port (
389
                        -- The usual control signals.
390
                clk,rst : in std_logic;
391
 
392
                -- Grid, rays and sphere flow through control signals.
393
                pipeOn                  : in std_logic;
394
                -- The same column nxtSphere signal control..... regardless the Cube Depth.
395
                nxtSphere               : in std_logic_vector (C-1 downto 0);
396
 
397
                -- R-F0
398
                -- Input Values. 
399
                -- The ray input vector. 
400
                iRayx: in std_logic_vector (D*W0 - 1 downto 0);
401
                iRayy: in std_logic_vector (D*W0 - 1 downto 0);
402
                iRayz: in std_logic_vector (D*W0 - 1 downto 0);
403
                -- The spheres x position (sphere centers) input vectors.
404
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
405
                -- The spheres y position (sphere centers) input vectors.
406
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
407
                -- The spheres z position (sphere centers) input vectors.
408
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
409
                -- The spheres x position (sphere centers) output vectors.
410
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
411
                -- The spheres y positions (sphere centes) output vectors.
412
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
413
                -- The spheres z positions (sphere centers) output vectors.             
414
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
415
                -- Output Values
416
                -- The ray output vector.
417
                oRayx: out std_logic_vector (D*W0 - 1 downto 0);
418
                oRayy: out std_logic_vector (D*W0 - 1 downto 0);
419
                oRayz: out std_logic_vector (D*W0 - 1 downto 0);
420
 
421
                -- R-F1
422
                -- K Input / Output.
423
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
424
                kOutput : out std_logic_vector (C*W1 - 1 downto 0)
425
 
426
                --R-F2
427
                -- Input Values
428
                refvd   : in std_logic_vector (D*W1-1 downto 0);
429
                selvd   : out std_logic_vector (D*W1-1 downto 0);
430
                colid   : out std_logic_vector (D*IDW-1 downto 0);
431
                inter   : out std_logic_vector (D-1 downto 0)
432
                );
433
        end component;
434 22 jguarin200
end powerGrid;

powered by: WebSVN 2.1.0

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