URL
https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk
Subversion Repositories theia_gpu
Compare Revisions
- This comparison shows the changes necessary to convert path
/theia_gpu/branches/beta_1.2/rtl/GEO
- from Rev 82 to Rev 87
- ↔ Reverse comparison
Rev 82 → Rev 87
/Module_TreeNodeFetcher.v
0,0 → 1,541
`timescale 1ns / 1ps |
`include "aDefinitions.v" |
/********************************************************************************** |
Theia, Ray Cast Programable graphic Processing Unit. |
Copyright (C) 2010 Diego Valverde (diego.valverde.g@gmail.com) |
|
This program is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License |
as published by the Free Software Foundation; either version 2 |
of the License, or (at your option) any later version. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
***********************************************************************************/ |
`define TNF_AFTER_RESET 0 |
`define TNF_IDLE 1 |
`define TNF_REQUEST_AABBMIN 2 |
`define TNF_WAIT_FOR_AABBMIN 3 |
`define TNF_REQUEST_AABBMAX 4 |
`define TNF_WAIT_FOR_AABBMAX 5 |
|
`define TNF_REQUEST_NUMBER_OF_TRIANGLES 10 |
`define TNF_WAIT_FOR_NUMBER_OF_TRIANGLES 11 |
`define TNF_LATCH_NUMBER_OF_TRIANGLES 12 |
`define TNF_WAIT_NODE_READ_ACK 13 |
`define TNF_REQUEST_DATA_OFFSET 14 |
`define TNF_WAIT_FOR_DATA_OFFSET 15 |
`define TNF_LATCH_DATA_OFFSET 16 |
`define TNF_REQUEST_NODE_BROTHER_ADDRESS 17 |
`define TNF_WAIT_FOR_NODE_BROTHER_ADDRESS 18 |
`define TNF_LACTH_NODE_BROTHER_ADDRESS 19 |
`define TNF_REQUEST_NODE_PARENT_BROTHER_ADDRESS 20 |
`define TNF_WAIT_NODE_PARENT_BROTHER_ADDRESS 21 |
`define TNF_LATCH_NODE_PARENT_BROTHER_ADDRESS 22 |
`define TNF_RAM_WRITE_DELAY1 23 |
`define TNF_INC1 24 |
`define TNF_INC2 25 |
`define TNF_INC3 26 |
|
/* |
|
To fetch node, we need to ask WBM to perform several read cycles. |
Each read cycle reads 32 bits. The first 6 read cycles requests |
consecutive addresses that represent AABBMAX and AABBMIN corners. |
These 6 values must be stored into RAM for the ucode to use. |
Next value represents the number of vertices this AABB has, or |
zero is is not a LEAF. |
Next value is the offset where of the vertex data. |
*/ |
|
module TreeNodeFetcher |
( |
input wire Clock, |
input wire Reset, |
input wire[`WIDTH-1:0] iData, |
input wire iDataAvailable, |
input wire iTrigger, |
input wire[`WIDTH-1:0] iInitialAddress, |
|
//wires that go into WBM |
output reg oSetAddressWBM, |
output reg oEnableWBM, |
output wire[`WIDTH-1:0] oAddressWBM, |
//The parsed node info |
output wire oNode_IsLeaf, |
output wire[`WIDTH-1:0] oNode_DataOffset, |
output wire [`WIDTH-1:0] oNode_TriangleCount, //Change to 16 bits |
//output wire [`WIDTH-1:0] oNode_ChildCount, //Change to 16 bits |
|
output wire [`WIDTH-1:0] oNode_Brother_Address, //* |
output wire [`WIDTH-1:0] oParents_Brother_Address, //* |
//output reg [`WIDTH-1:0] oNode_FirstChild_Address, |
|
output reg oNodeReadDone, |
output reg oRAMWriteEnable, |
|
`ifdef DEBUG |
input wire[`MAX_CORES-1:0] iDebug_CoreID, |
`endif |
|
output reg [`DATA_ADDRESS_WIDTH-1:0] oRAMWriteAddress |
); |
|
reg [4:0] CurrentState; |
reg [4:0] NextState; |
|
|
assign oAddressWBM = iInitialAddress; |
|
reg rFFEnNumVertices; |
|
//Flip Flop D |
//FFD_SYNCH_RST_GENERIC FFD32_TNF |
FFD_POSEDGE_SYNCRONOUS_RESET # (`WIDTH) FFD32_TNF |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.Enable( rFFEnNumVertices ), |
.D( iData ), |
.Q( oNode_TriangleCount ) |
|
); |
|
|
reg rFFEnBrotherAddress; |
//Flip Flop D |
FFD_POSEDGE_SYNCRONOUS_RESET # (`WIDTH) FFD32_TNF_NC |
//FFD_SYNCH_RST_GENERIC FFD32_TNF_NC |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.Enable( rFFEnBrotherAddress ), |
.D( iData ), |
.Q( oNode_Brother_Address ) |
|
); |
|
reg rFFEnParentsBroAddr; |
//Flip Flop D |
FFD_POSEDGE_SYNCRONOUS_RESET # (`WIDTH) FFD32_TNF_NC2 |
//FFD_SYNCH_RST_GENERIC FFD32_TNF_NC2 |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.Enable( rFFEnParentsBroAddr ), |
.D( iData ), |
.Q( oParents_Brother_Address ) |
|
); |
|
|
reg rFFEnDataOffset; |
//Flip Flop D |
FFD_POSEDGE_SYNCRONOUS_RESET # (`WIDTH) FFD32_TNF2 |
//FFD_SYNCH_RST_GENERIC FFD32_TNF2 |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.Enable( rFFEnDataOffset ), |
.D( iData ), |
.Q( oNode_DataOffset ) |
|
); |
|
|
assign oNode_IsLeaf = (oNode_TriangleCount != 32'h0); |
|
//------------------------------------------------ |
always @(posedge Clock or posedge Reset) |
begin |
|
if (Reset) |
CurrentState <= `TNF_AFTER_RESET; |
else |
CurrentState <= NextState; |
|
end |
|
//------------------------------------ |
/* |
IDLE State just waiting for something |
to do... |
*/ |
|
always @( * ) |
begin |
case (CurrentState) |
//------------------------------------ |
`TNF_AFTER_RESET: |
begin |
|
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
oRAMWriteEnable <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_IDLE; |
end |
//------------------------------------ |
`TNF_IDLE: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
oRAMWriteEnable <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if (iTrigger) |
NextState <= `TNF_REQUEST_AABBMIN; |
else |
NextState <= `TNF_IDLE; |
|
end |
//------------------------------------ |
/* |
Here tell WBM to read from address iInitialAddress by seeting |
oSetAddressWBM = 1. |
By setting oRAMWriteEnable = 1, we are also telling WBM to |
store the the value in iInitialAddress, iInitialAddress+1, |
and iInitialAddress+2 into RAM, so the WBMAddress is going |
to increment by 3. |
*/ |
`TNF_REQUEST_AABBMIN: |
begin |
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d TNF_REQUEST_AABBMIN",iDebug_CoreID); |
`endif |
|
oRAMWriteAddress <= `CREG_AABBMIN; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 1; //* |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 1; //* |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_WAIT_FOR_AABBMIN; |
|
end |
//------------------------------------ |
`TNF_WAIT_FOR_AABBMIN: |
begin |
oRAMWriteAddress <= `CREG_AABBMIN; |
oEnableWBM <= 1; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 1;//* |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_REQUEST_AABBMAX; |
else |
NextState <= `TNF_WAIT_FOR_AABBMIN; |
end |
//------------------------------------ |
`TNF_REQUEST_AABBMAX: |
begin |
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d TNF_REQUEST_AABBMAX",iDebug_CoreID); |
`endif |
oRAMWriteAddress <= `CREG_AABBMAX; |
oEnableWBM <= 1; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 1;//* |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_WAIT_FOR_AABBMAX; |
end |
//------------------------------------ |
`TNF_WAIT_FOR_AABBMAX: |
begin |
oRAMWriteAddress <= `CREG_AABBMAX; |
oEnableWBM <= 1; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 1;//* |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_REQUEST_NUMBER_OF_TRIANGLES; |
else |
NextState <= `TNF_WAIT_FOR_AABBMAX; |
end |
//------------------------------------ |
`TNF_REQUEST_NUMBER_OF_TRIANGLES: |
begin |
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d TNF_REQUEST_NUMBER_OF_TRIANGLES",iDebug_CoreID); |
`endif |
oRAMWriteAddress <= `CREG_AABBMAX; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; //* to give more time to write |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_WAIT_FOR_NUMBER_OF_TRIANGLES; |
end |
//------------------------------------ |
`TNF_WAIT_FOR_NUMBER_OF_TRIANGLES: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
oRAMWriteEnable <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_LATCH_NUMBER_OF_TRIANGLES; |
else |
NextState <= `TNF_WAIT_FOR_NUMBER_OF_TRIANGLES; |
|
end |
//------------------------------------ |
`TNF_LATCH_NUMBER_OF_TRIANGLES: |
begin |
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d TNF_LATCH_NUMBER_OF_TRIANGLES",iDebug_CoreID); |
`endif |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; //* |
rFFEnNumVertices <= 1; |
rFFEnDataOffset <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
oRAMWriteEnable <= 0; |
|
NextState <= `TNF_REQUEST_DATA_OFFSET; |
end |
//------------------------------------ |
`TNF_REQUEST_DATA_OFFSET: |
begin |
|
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_WAIT_FOR_DATA_OFFSET; |
end |
//------------------------------------ |
`TNF_WAIT_FOR_DATA_OFFSET: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_LATCH_DATA_OFFSET; |
else |
NextState <= `TNF_WAIT_FOR_DATA_OFFSET; |
|
end |
//------------------------------------ |
`TNF_LATCH_DATA_OFFSET: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 1; //* |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_REQUEST_NODE_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_REQUEST_NODE_BROTHER_ADDRESS: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 1; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_WAIT_FOR_NODE_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_WAIT_FOR_NODE_BROTHER_ADDRESS: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_LACTH_NODE_BROTHER_ADDRESS; |
else |
NextState <= `TNF_WAIT_FOR_NODE_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_LACTH_NODE_BROTHER_ADDRESS: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 1; //* |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_REQUEST_NODE_PARENT_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_REQUEST_NODE_PARENT_BROTHER_ADDRESS: |
begin |
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d TNF_REQUEST_NODE_PARENT_BROTHER_ADDRESS",iDebug_CoreID); |
`endif |
|
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; //* |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
//rLastAddress <= 1; |
|
NextState <= `TNF_WAIT_NODE_PARENT_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_WAIT_NODE_PARENT_BROTHER_ADDRESS: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 1; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iDataAvailable ) |
NextState <= `TNF_LATCH_NODE_PARENT_BROTHER_ADDRESS; |
else |
NextState <= `TNF_WAIT_NODE_PARENT_BROTHER_ADDRESS; |
end |
//------------------------------------ |
`TNF_LATCH_NODE_PARENT_BROTHER_ADDRESS: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 1; |
|
NextState <= `TNF_WAIT_NODE_READ_ACK; |
|
end |
//------------------------------------ |
`TNF_WAIT_NODE_READ_ACK: |
begin |
|
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 1; //* |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
if ( iTrigger == 0 ) |
NextState <= `TNF_IDLE; |
else |
NextState <= `TNF_WAIT_NODE_READ_ACK; |
end |
//------------------------------------ |
default: |
begin |
oRAMWriteAddress <= 0; |
oEnableWBM <= 0; |
oSetAddressWBM <= 0; |
oNodeReadDone <= 0; |
rFFEnNumVertices <= 0; |
rFFEnDataOffset <= 0; |
oRAMWriteEnable <= 0; |
rFFEnBrotherAddress <= 0; |
rFFEnParentsBroAddr <= 0; |
|
NextState <= `TNF_IDLE; |
end |
//------------------------------------ |
endcase |
end //always |
endmodule |
/Module_GeometryFetchFSM.v
0,0 → 1,1429
/********************************************************************************** |
Theaia, Ray Cast Programable graphic Processing Unit. |
Copyright (C) 2009 Diego Valverde (diego.valverde.g@gmail.com) |
|
This program is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License |
as published by the Free Software Foundation; either version 2 |
of the License, or (at your option) any later version. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
***********************************************************************************/ |
|
/********************************************************************************** |
Module Description: |
|
WIP |
**********************************************************************************/ |
|
|
`timescale 1ns / 1ps |
`include "aDefinitions.v" |
|
`define GFSM_AFTER_RESET 0 |
`define GFSM_INITIAL_STATE 1 |
`define GFSM_TRIGGER_AABBIU 2 |
`define GFSM_WAIT_FOR_AABBIU 3 |
`define GFSM_ACK_AABBIU 10 |
`define GFSM_AABBIU_HIT 4 |
`define GFSM_AABBIU_NO_HIT 5 |
`define GFSM_TRIGGER_TRIANGLE_FETCH 6 |
`define GFSM_WAIT_FOR_TRIANGLE_FETCH 7 |
`define GFSM_TRIGGER_BIU_REQUSET 8 |
`define GFSM_WAIT_FOR_BIU 9 |
`define GFSM_GET_FIRST_CHILD 11 |
`define GFSM_CHECK_TRIANGLE_COUNT 12 |
`define GFSM_CHECK_NEXT_BROTHER 13 |
`define GFSM_GET_BROTHER 14 |
`define GFSM_TRIGGER_NODE_FETCH 15 |
`define GFSM_FETCH_NEXT_BROTHER 16 |
`define GFSM_CHECK_PARENTS_BROTHER 18 |
`define GFSM_GET_PARENTS_BROTHER 19 |
`define GFSM_WAIT_FOR_NODE_FETCH 20 |
`define GFSM_POST_BLOCK_READ_DELAY 21 |
`define GFSM_TRIGGER_ROOT_NODE_FETCH 23 |
`define GFSM_WAIT_FOR_ROOT_NODE_FETCH 24 |
`define GFSM_FETCH_DATA 25 |
`define GFSM_WAITF_FOR_BIU_AVAILABLE 26 |
`define GFSM_SWAP_TRIANGLE_POINTER 27 |
`define GFSM_DONE 28 |
`define GFSM_SET_TRIANGLE_LIST_INITIAL_OFFSET 29 |
`define GFSM_REQUEST_TCC 30 |
`define GFSM_WAIT_FOR_TCC 31 |
`define GFSM_WAIT_STATE_PRE_TCC 32 |
`define GFSM_INITIAL_STATE_TEXTURE 33 |
`define GFSM_SET_WBM_INITIAL_ADDRESS 34 |
`define GFSM_REQUEST_TEXTURE 35 |
`define GFSM_WAIT_FOR_TEXTURE 36 |
`define GFSM_REQUEST_NEXT_TEXTURE 37 |
`define GFSM_WAIT_FOR_NEXT_TEXTURE 38 |
`define GFSM_INC_TEXTURE_ADDRESS 39 |
`define GFSM_SET_NEXT_TEXTURE_ADDR 42 |
`define GFSM_WAIT_FOR_IO_HIT 43 |
`define GFSM_WAIT_FOR_IO_NO_HIT 44 |
|
|
module GeometryFetchFSM |
( |
input wire Clock, |
input wire Reset, |
//Input control signals |
input wire iEnable, |
input wire iAABBIUHit, |
input wire iBIUHit, |
input wire iUCodeDone, |
input wire iTexturingEnable, |
input wire iTriangleReadDone, |
//input wire iTextureReadDone, |
input wire iNodeReadDone, |
|
//Current Node info |
input wire iNode_IsLeaf, |
input wire[`WIDTH-1:0] iNode_Brother_Address, |
input wire[`WIDTH-1:0] iNode_TriangleCount, |
input wire[`WIDTH-1:0] iNode_Parents_Brother_Address, |
//input wire[`WIDTH-1:0] Node_OffsetData_Address, |
input wire[`WIDTH-1:0] iNode_FirstChild_Address, |
//input wire iBIUAvailable, |
//input wire Node_MaxBlocks, |
|
//Control output signals |
output reg oEnable_WBM, //Activate the WBM in I/O |
output wire[`DATA_ADDRESS_WIDTH-1:0] oAddressWBM, //This is the address that we want to read from in I/O |
output reg oSetAddressWBM, //This uis to tell I/O to use the adress we just set |
output reg oSetIOWriteBackAddr, |
output wire[`DATA_ADDRESS_WIDTH-1:0] oRAMTextureStoreLocation, //This is where we want to store the data comming from I/O |
input wire iDataAvailable, |
input wire iIOBusy, |
|
|
output reg [`WIDTH-1:0] oNodeAddress, |
input wire iTrigger_TFF, |
|
output reg oRequest_AABBIU, |
output reg oRequest_BIU, |
output reg oRequest_TCC, |
output reg oTrigger_TFU, |
output reg oTrigger_TNF, |
output reg [1:0] oWBM_Addr_Selector, //0 = TNF, 1 = TFU, 2 = TCC |
output reg oSync, |
output reg oSetTFUAddressOffset, |
`ifdef DEBUG |
input wire[`MAX_CORES-1:0] iDebug_CoreID, |
`endif |
output reg oDone |
|
|
); |
|
|
|
|
|
reg [6:0] CurrentState; |
reg [6:0] NextState; |
//reg //IncTextureWriteAddress; |
reg IncTextureCoordRegrAddr,IncTextureCount; |
wire [2:0] wTextureCount; |
|
reg IncTriangleCount,ClearTriangleCount; |
wire [`WIDTH-1:0] wTriangleCount; |
|
//---------------------------------------- |
UpCounter_32 UP32_Tricount |
( |
|
.Clock( Clock ), |
.Reset( ClearTriangleCount ), |
.Initial( 0 ), |
.Enable( IncTriangleCount ), |
.Q( wTriangleCount ) |
|
); |
//----------------------------- |
|
UpCounter_16E TFF_VC1a |
( |
.Clock( Clock ), |
.Reset( iTrigger_TFF | Reset ), |
.Initial( `OREG_TEX_COORD1 ), |
.Enable( IncTextureCoordRegrAddr ), |
.Q( oAddressWBM ) |
); |
|
//assign oAddressWBM = `OREG_TEX_COORD1; |
|
//----------------------------- |
|
UPCOUNTER_POSEDGE # (3) TFF_VC1 |
( |
.Clock( Clock ), |
.Reset( iTrigger_TFF ), |
.Initial( 3'b0 ), |
.Enable( IncTextureCount ), |
.Q( wTextureCount ) |
); |
|
//----------------------------- |
assign oRAMTextureStoreLocation = `CREG_TEX_COLOR1; |
/* |
UPCOUNTER_POSEDGE # (16) TNF_TFU_2 |
( |
|
.Clock( Clock ), |
.Reset( iTrigger_TFF ), |
.Initial( `CREG_TEX_COLOR1 ), |
.Enable( //IncTextureWriteAddress ), |
.Q( oRAMTextureStoreLocation ) |
|
); |
*/ |
|
//---------------------------------------- |
`define GFSM_SELECT_TFU 2'b00 //Triangle Fetch |
`define GFSM_SELECT_TFF 2'b01 //Texture Fetch |
`define GFSM_SELECT_TNF 2'b10 //Tree node fetch |
`define GFSM_SELECT_NULL 2'b11 |
|
//------------------------------------------------ |
always @(posedge Clock or posedge Reset) |
begin |
|
|
|
if (Reset) |
CurrentState <= `GFSM_AFTER_RESET; |
else |
CurrentState <= NextState; |
|
end |
//------------------------------------------------ |
|
always @( * ) |
begin |
case (CurrentState) |
//------------------------------------------ |
`GFSM_AFTER_RESET: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_INITIAL_STATE; |
end |
//------------------------------------------ |
/* |
Here two things ca happen: |
1) We are onGeometry Fetch Mode (iTrigger_TFF == 0) |
then get the first node in the Octant Tree, or, |
2)We are on Texture Fetch Mode (iTrigger_TFF == 1) |
then do texture fetch stuff... |
*/ |
`GFSM_INITIAL_STATE: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 1; //* |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iEnable && !iTrigger_TFF ) |
NextState <= `GFSM_TRIGGER_ROOT_NODE_FETCH; |
else if (iEnable && iTrigger_TFF) |
NextState <= `GFSM_SET_WBM_INITIAL_ADDRESS; |
else |
NextState <= `GFSM_INITIAL_STATE; |
end |
//------------------------------------------ |
`GFSM_SET_WBM_INITIAL_ADDRESS: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 1; //* |
oSetIOWriteBackAddr <= 1; //Make sure we set write back address |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
|
|
NextState <= `GFSM_REQUEST_TEXTURE; |
|
end |
//------------------------------------ |
`GFSM_REQUEST_TEXTURE: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
//$display("GFSM_REQUEST_TEXTURE: Texture Addr in Reg: %d",oAddressWBM); |
oEnable_WBM <= 1; //* |
oSetAddressWBM <= 0; |
IncTextureCount <= 0; //* |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
|
|
NextState <= `GFSM_WAIT_FOR_TEXTURE; |
end |
//------------------------------------ |
`GFSM_WAIT_FOR_TEXTURE: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
|
oEnable_WBM <= 1; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `CREG_TEX_COLOR1; |
|
if ( iDataAvailable ) |
NextState <= `GFSM_INC_TEXTURE_ADDRESS; |
else |
NextState <= `GFSM_WAIT_FOR_TEXTURE; |
|
end |
//------------------------------------ |
`GFSM_INC_TEXTURE_ADDRESS: |
begin |
//$display("***** GFSM_REQUEST_NEXT_TEXTURE: Texture Addr in Reg: %d",oAddressWBM); |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
IncTextureCount <= 1; |
//IncTextureWriteAddress <= 0;//1; |
IncTextureCoordRegrAddr <= 1; //* |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `CREG_TEX_COLOR4; |
|
NextState <= `GFSM_SET_NEXT_TEXTURE_ADDR; |
end |
//------------------------------------ |
`GFSM_SET_NEXT_TEXTURE_ADDR: |
begin |
|
//$display("***** GFSM_REQUEST_NEXT_TEXTURE: Texture Addr in Reg: %d",oAddressWBM); |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; //* |
oSetAddressWBM <= 1; |
IncTextureCount <= 0; //* |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `CREG_TEX_COLOR4; |
|
|
NextState <= `GFSM_REQUEST_NEXT_TEXTURE; |
end |
//------------------------------------ |
/* |
We request 6 textures (ie. six colors from |
the texture coordinates, it should be actually 4 |
instead of 6, but the hardwardware works better |
with numbers that are power of 3. But read 3 at |
a time, so when TextureCount Reaches 2 then we |
are done |
*/ |
`GFSM_REQUEST_NEXT_TEXTURE: |
begin |
|
//$display("***** GFSM_REQUEST_NEXT_TEXTURE: Texture Addr in Reg: %d",oAddressWBM); |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 1; //* |
oSetAddressWBM <= 0; |
IncTextureCount <= 1; //* |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `CREG_TEX_COLOR4; |
|
|
NextState <= `GFSM_WAIT_FOR_NEXT_TEXTURE; |
end |
|
//---------------------------------------- |
`GFSM_WAIT_FOR_NEXT_TEXTURE: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
|
oEnable_WBM <= 1; |
oSetAddressWBM <= 0; |
IncTextureCount <= 0; //* |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `CREG_TEX_COLOR4; |
|
if ( iDataAvailable ) |
NextState <= `GFSM_DONE; |
else |
NextState <= `GFSM_WAIT_FOR_NEXT_TEXTURE; |
|
end |
/****************************************/ |
/* |
Texture Fetch Logic Ends Here. |
Geometry Fetch Logic Starts Here (Duh!) |
*/ |
//------------------------------------ |
/* |
Lets request the Root Node read in here. |
The tree node function will fetch info such as |
the type of node, the address of the first |
data block as well as the boundaries of the |
AABB. |
*/ |
`GFSM_TRIGGER_ROOT_NODE_FETCH: |
begin |
|
`ifdef DEBUG_GFSM |
if (iDebug_CoreID == `DEBUG_CORE) |
$display("CORE %d GFSM_TRIGGER_ROOT_NODE_FETCH",iDebug_CoreID); |
`endif |
|
|
oNodeAddress <= 0; //Address of root node is always zero |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 1; //* |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TNF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_WAIT_FOR_ROOT_NODE_FETCH; |
|
end |
//------------------------------------------ |
/* |
OK once we have the data the first ting is |
to test if the ray hits the AABB. |
*/ |
`GFSM_WAIT_FOR_ROOT_NODE_FETCH: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0;//* |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TNF; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if (iNodeReadDone) |
NextState <= `GFSM_TRIGGER_AABBIU; |
else |
NextState <= `GFSM_WAIT_FOR_ROOT_NODE_FETCH; |
end |
//------------------------------------------ |
/* |
So, while we request AABBIU, we should be requesting |
the info for the Next triangle as well... |
*/ |
`GFSM_TRIGGER_AABBIU: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 1; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; //WIP!!!!!!!! |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 1; //* |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_WAIT_FOR_AABBIU; |
end |
//------------------------------------------ |
`GFSM_WAIT_FOR_AABBIU: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 1; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iUCodeDone ) |
NextState <= `GFSM_ACK_AABBIU; |
else |
NextState <= `GFSM_WAIT_FOR_AABBIU; |
end |
//------------------------------------------ |
`GFSM_ACK_AABBIU: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iAABBIUHit ) |
NextState <= `GFSM_AABBIU_HIT; |
else |
NextState <= `GFSM_AABBIU_NO_HIT; |
end |
//------------------------------------------ |
`GFSM_AABBIU_NO_HIT: |
begin |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_DONE; |
end |
//------------------------------------------ |
/* |
Ok there is a hit, two things can happen: |
if the Node is not a leaf, then the child nodes |
need to be tested. |
Else this node's data linked list needs |
to be tested for instersections. |
Since we have a new Node, lets start by |
reading the first 3 blocks of data. The |
first block is pointed by |
'Node_OffsetData_Address'. |
*/ |
`GFSM_AABBIU_HIT: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iNode_IsLeaf ) |
NextState <= `GFSM_SET_TRIANGLE_LIST_INITIAL_OFFSET; |
else |
NextState <= `GFSM_GET_FIRST_CHILD; |
end |
//------------------------------------------ |
`GFSM_SET_TRIANGLE_LIST_INITIAL_OFFSET: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 1; //* |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_TRIGGER_TRIANGLE_FETCH; |
end |
//------------------------------------------ |
/* |
Since this node is not a leaf, we keep depth |
first deep traversing the hierchy |
*/ |
`GFSM_GET_FIRST_CHILD: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= iNode_FirstChild_Address; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_TRIGGER_NODE_FETCH; |
end |
//------------------------------------------ |
/* |
|
*/ |
`GFSM_CHECK_TRIANGLE_COUNT: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
|
if ( wTriangleCount == iNode_TriangleCount ) |
NextState <= `GFSM_CHECK_NEXT_BROTHER; |
else |
NextState <= |
//`GFSM_TRIGGER_TRIANGLE_FETCH; |
`GFSM_TRIGGER_BIU_REQUSET; //NEW NEW PARALLEL IO |
end |
//------------------------------------------ |
`GFSM_TRIGGER_TRIANGLE_FETCH: |
begin |
|
|
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 1; //* |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFU; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_WAIT_FOR_TRIANGLE_FETCH; |
end |
//------------------------------------------ |
|
/* |
iEnable the data fetch and wait for the |
operation to complete. |
*/ |
`GFSM_WAIT_FOR_TRIANGLE_FETCH: |
begin |
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; //* |
oTrigger_TNF <= 0; |
ClearTriangleCount <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFU; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iTriangleReadDone ) |
NextState <= `GFSM_TRIGGER_BIU_REQUSET; |
else |
NextState <= `GFSM_WAIT_FOR_TRIANGLE_FETCH; |
end |
|
//------------------------------------------ |
/* |
Now that we got the traingle vertices in RAM, |
lets iEnable the BIU micro-code sub. |
*/ |
`GFSM_TRIGGER_BIU_REQUSET: |
begin |
|
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 1; //* |
oTrigger_TFU <= |
//0; |
1; ///NEW NEW NEW Jan 25 2010, try to put this to 1 |
oTrigger_TNF <= 0; |
IncTriangleCount <= 1; //* |
ClearTriangleCount <= 0; |
oWBM_Addr_Selector <= |
//`GFSM_SELECT_NULL; |
`GFSM_SELECT_TFU; //NEW NEW Paralell IO |
oSync <= 1;//* |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_WAIT_FOR_BIU; |
end |
//------------------------------------------ |
/* |
Once BIU finishes see have a hit. |
There are severals paths to go here depnending on |
wethher there was a Hit or Not, and also depending |
on whether we the texturing capability enabled. |
1) If there was a Hit, but the textures are not enabled, |
then keep interating the triangle list. |
2) If there was a Hit and the texturing is enabled, |
then go to the state that request the texture |
coordiantes calculation |
3) If there was not a Hit, then keep traversong the |
triangle list. |
4) If there is neither Hit or no-Hit yet, then keep |
waiting is this state. |
*/ |
`GFSM_WAIT_FOR_BIU: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 1; //* |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= |
//`GFSM_SELECT_NULL; |
`GFSM_SELECT_TFU; //NEW NEW Paralell IO |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
/* |
if (iUCodeDone & iBIUHit & ~iTriangleReadDone & iTexturingEnable) |
NextState <= `GFSM_WAIT_FOR_IO_HIT; |
else if (iUCodeDone & ~iBIUHit & ~iTriangleReadDone & iTexturingEnable) |
NextState <= `GFSM_WAIT_FOR_IO_NO_HIT; |
else |
NextState <= `GFSM_WAIT_FOR_BIU; |
*/ |
|
if (iUCodeDone && iBIUHit && !iTexturingEnable && !iIOBusy)//Change IOBusy for TFUDone!!! |
NextState <= `GFSM_CHECK_TRIANGLE_COUNT; |
else if (iUCodeDone && iBIUHit && iTexturingEnable && !iIOBusy) |
NextState <= `GFSM_WAIT_STATE_PRE_TCC; |
else if (iUCodeDone && iBIUHit && iTexturingEnable && iIOBusy) |
NextState <= `GFSM_WAIT_FOR_IO_HIT; |
else if (iUCodeDone && !iBIUHit && !iIOBusy) |
NextState <= `GFSM_CHECK_TRIANGLE_COUNT; |
else if (iUCodeDone && !iBIUHit && iIOBusy) |
NextState <= `GFSM_WAIT_FOR_IO_NO_HIT; |
else |
NextState <= `GFSM_WAIT_FOR_BIU; |
|
|
end |
//------------------------------------------ |
`GFSM_WAIT_FOR_IO_HIT: |
begin |
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 1; //* |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_TFU; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
|
if (iTriangleReadDone ) |
NextState <= `GFSM_WAIT_STATE_PRE_TCC; |
else |
NextState <= `GFSM_WAIT_FOR_IO_HIT; |
|
end |
//------------------------------------------ |
`GFSM_WAIT_FOR_IO_NO_HIT: |
begin |
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 1; //* |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_TFU; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
|
if (iTriangleReadDone ) |
NextState <= `GFSM_CHECK_TRIANGLE_COUNT; |
else |
NextState <= `GFSM_WAIT_FOR_IO_NO_HIT; |
|
end |
//------------------------------------------ |
/* |
Need to wait a extra cycle so that control unit will be able |
to get into the wait from geo sync state...it sucks I know... |
*/ |
`GFSM_WAIT_STATE_PRE_TCC: |
begin |
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 1; //* |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
NextState <= `GFSM_REQUEST_TCC; |
end |
//------------------------------------------ |
|
/* |
This state request CU to trigger TCC, ie the code |
that is responsible of generating the 4 |
memory addresses to get the texture coordinates: |
ie: OREG_TEX_COORD1 and OREG_TEX_COORD2, this coordinates are stored, and |
they replace the previous coordinates values only |
if the current traingle is closer to the camera. |
*/ |
`GFSM_REQUEST_TCC: |
begin |
|
// $display("%d GFSM_REQUEST_TCC",$time); |
// $display("GFSM_REQUEST_TCC %d oRequest_TCC = %d",$time,oRequest_TCC); |
|
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 1; //* |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 1; //* |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_WAIT_FOR_TCC; |
|
end |
//------------------------------------------ |
/* |
If the textures coordinates are calculted then |
move into the next triangle. |
*/ |
`GFSM_WAIT_FOR_TCC: |
begin |
|
// $display("GFSM_WAIT_FOR_TCC %d oSync = %d",$time,oSync); |
// $display("GFSM_WAIT_FOR_TCC %d oRequest_TCC = %d",$time,oRequest_TCC); |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 1; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if (iUCodeDone) |
NextState <= `GFSM_CHECK_TRIANGLE_COUNT; |
else |
NextState <= `GFSM_WAIT_FOR_TCC; |
end |
//------------------------------------------ |
/* `GFM_TRIGGER_TEXTURE_FETCH: |
begin |
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= 0; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oTrigger_TFF <= 1; |
|
NextState <= `GFSM_WAIT_FOR_TEXTURE_FETCH; |
end |
|
//------------------------------------------ |
`GFSM_WAIT_FOR_TEXTURE_FETCH: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; |
oWBM_Addr_Selector <= 0; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oTrigger_TFF <= 0; |
|
if (iTextureReadDone == 1'b1) |
NextState <= `GFSM_CHECK_TRIANGLE_COUNT; |
else |
NextState <= `GFSM_WAIT_FOR_TEXTURE_FETCH; |
|
end |
*/ |
//------------------------------------------ |
`GFSM_CHECK_NEXT_BROTHER: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iNode_Brother_Address == 0 ) |
NextState <= `GFSM_CHECK_PARENTS_BROTHER; |
else |
NextState <= `GFSM_GET_BROTHER; |
end |
//------------------------------------------ |
`GFSM_GET_BROTHER: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= iNode_Brother_Address; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_TRIGGER_NODE_FETCH; |
end |
//------------------------------------------ |
`GFSM_CHECK_PARENTS_BROTHER: |
begin |
|
|
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if ( iNode_Parents_Brother_Address == 0) |
NextState <= `GFSM_DONE; |
else |
NextState <= `GFSM_GET_PARENTS_BROTHER; |
end |
//------------------------------------------ |
`GFSM_GET_PARENTS_BROTHER: |
begin |
oRequest_AABBIU <= 0; |
oNodeAddress <= iNode_Parents_Brother_Address; //* |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_TRIGGER_NODE_FETCH; |
end |
//------------------------------------------ |
`GFSM_TRIGGER_NODE_FETCH: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= iNode_Brother_Address; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 1; //* |
oTrigger_TNF <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
IncTriangleCount <= 0; //* |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_WAIT_FOR_NODE_FETCH; |
end |
//------------------------------------------ |
/* |
Lets read the new node in our linked list. |
Once we got it we need to check AABB intersect, |
fetch traingles, etc, etc. |
*/ |
`GFSM_WAIT_FOR_NODE_FETCH: |
begin |
|
oRequest_AABBIU <= 0; |
oNodeAddress <= iNode_Brother_Address; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 1; |
oTrigger_TNF <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_TFU; |
IncTriangleCount <= 0; //* |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
if (iNodeReadDone) |
NextState <= `GFSM_TRIGGER_AABBIU; |
else |
NextState <= `GFSM_WAIT_FOR_NODE_FETCH; |
end |
//------------------------------------------ |
`GFSM_DONE: |
begin |
|
`ifdef DEBUG2 |
$display(" **** GFSM_DONE ***"); |
`endif |
oNodeAddress <= 0; |
oRequest_AABBIU <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
ClearTriangleCount <= 0; |
oSync <= 1; //* |
oDone <= 1; //* |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
if (iEnable == 0 ) |
NextState <= `GFSM_INITIAL_STATE; |
else |
NextState <= `GFSM_DONE; |
end |
//------------------------------------------ |
default: |
begin |
|
|
oRequest_AABBIU <= 0; |
oNodeAddress <= 0; |
oRequest_BIU <= 0; |
oTrigger_TFU <= 0; |
oTrigger_TNF <= 0; |
oWBM_Addr_Selector <= `GFSM_SELECT_NULL; |
IncTriangleCount <= 0; //* |
oWBM_Addr_Selector <= 0; |
ClearTriangleCount <= 0; |
oSync <= 0; |
oDone <= 0; |
oSetTFUAddressOffset <= 0; |
oRequest_TCC <= 0; |
|
oEnable_WBM <= 0; |
oSetAddressWBM <= 0; |
//IncTextureWriteAddress <= 0; |
IncTextureCount <= 0; |
IncTextureCoordRegrAddr <= 0; |
oSetIOWriteBackAddr <= 0; |
//oRAMTextureStoreLocation <= `DATA_ADDRESS_WIDTH'd0; |
|
|
NextState <= `GFSM_AFTER_RESET; |
end |
endcase |
end |
//------------------------------------------------ |
endmodule |
/Module_TriangleFetch.v
0,0 → 1,331
`timescale 1ns / 1ps |
`include "aDefinitions.v" |
|
`define TFU_AFTER_RESET 0 |
`define TFU_IDLE 1 |
`define TFU_REQUEST_VERTEX 2 |
`define TFU_WAIT_FOR_VERTEX 3 |
`define TFU_REQUEST_NEXT_VERTEX_DIFFUSE 4 |
`define TFU_REQUEST_DIFFUSE_COLOR 5 |
`define TFU_WAIT_FOR_DIFFUSE_COLOR 6 |
`define TFU_SET_WBM_INITIAL_ADDRESS 7 |
`define TFU_CHECK_FOR_WBM_ADDRESS_SET 8 |
`define TFU_SET_DIFFUSE_COLOR_ADDRESS 9 |
`define TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE 10 |
`define TFU_INC_WRITE_ADDRESS_DIFFUSE 11 |
`define TFU_DONE 12 |
/********************************************************************************** |
Theia, Ray Cast Programable graphic Processing Unit. |
Copyright (C) 2010 Diego Valverde (diego.valverde.g@gmail.com) |
|
This program is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License |
as published by the Free Software Foundation; either version 2 |
of the License, or (at your option) any later version. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
***********************************************************************************/ |
/* |
|
|
Warning: setting iTrigger while oBusy = 1 will reset the Up counters! |
|
*/ |
//------------------------------------------------------------------------- |
module TriangleFetchUnit |
( |
input wire Clock, |
input wire Reset, |
input wire iTrigger, |
//output reg oBusy, //I am currently busy |
output reg oDone, //Done reading trinagle data |
//Wires from GFSM |
input wire iDataAvailable, //Data is ready |
input wire[`WIDTH-1:0] iInitialAddress, //The initial address of the data |
input wire iSetAddressOffset, //Set the iInitialAddress Now |
//Wires from Control Register |
input wire iCR_TextureMappingEnabled, //Is the texture map fearure enable? |
|
//Wires to WBM |
output reg oTriggerWBM, |
output wire[`WIDTH-1:0] oAddressWBM, |
output reg oSetAddressWBM, |
output wire[`DATA_ADDRESS_WIDTH-1:0] oRAMWriteAddress, |
`ifdef DEBUG |
input wire[`MAX_CORES-1:0] iDebug_CoreID, |
`endif |
output reg oRAMWriteEnable |
|
); |
|
|
|
assign oAddressWBM = iInitialAddress;///Must change or will always read first triangle in the list.... |
|
|
reg [4:0] CurrentState,NextState; |
reg IncWriteAddress,IncVertexCount; |
wire [2:0] wVertexCount; |
//----------------------------- |
UpCounter_3 TNF_VC1 |
( |
.Clock( Clock ), |
.Reset( iTrigger ), |
.Initial( 3'b0 ), |
.Enable( IncVertexCount ), |
.Q( wVertexCount ) |
); |
|
|
//----------------------------- |
UpCounter_16E TNF_TFU_2 |
( |
|
.Clock( Clock ), |
.Reset( iTrigger ), |
.Initial( `CREG_V0 ),//iRAMWriteOffset ), |
.Enable( IncWriteAddress ), |
.Q( oRAMWriteAddress ) |
|
); |
|
//------------------------------------------------ |
always @(posedge Clock or posedge Reset) |
begin |
|
if (Reset) |
CurrentState <= `TFU_AFTER_RESET; |
else |
CurrentState <= NextState; |
|
end |
|
//------------------------------------ |
always @( * ) |
begin |
case (CurrentState) |
//------------------------------------ |
`TFU_AFTER_RESET: |
begin |
|
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 0; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
NextState <= `TFU_IDLE; |
end |
//------------------------------------ |
`TFU_IDLE: |
begin |
|
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 0; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
if ( iTrigger ) |
NextState <= `TFU_CHECK_FOR_WBM_ADDRESS_SET; |
else |
NextState <= `TFU_IDLE; |
|
end |
//------------------------------------ |
`TFU_CHECK_FOR_WBM_ADDRESS_SET: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 0; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
if ( iSetAddressOffset ) |
NextState <= `TFU_SET_WBM_INITIAL_ADDRESS; |
else |
NextState <= `TFU_REQUEST_VERTEX; |
|
end |
//------------------------------------ |
`TFU_SET_WBM_INITIAL_ADDRESS: |
begin |
|
`ifdef DEBUG |
$display("TFU: TFU_SET_WBM_INITIAL_ADDRESS"); |
`endif |
|
oTriggerWBM <= 0; |
oSetAddressWBM <= 1; //* |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 1; //* |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
NextState <= `TFU_REQUEST_VERTEX; |
end |
//------------------------------------ |
`TFU_REQUEST_VERTEX: |
begin |
oTriggerWBM <= 1; //* |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 1; //* |
// oBusy <= 1; |
oDone <= 0; |
oRAMWriteEnable <= 1; //* |
//$display("TFU_REQUEST_VERTEX %d to wirte to %d\n",oAddressWBM,oRAMWriteAddress); |
NextState <= `TFU_WAIT_FOR_VERTEX; |
end |
//------------------------------------ |
`TFU_WAIT_FOR_VERTEX: |
begin |
|
oTriggerWBM <= 1; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 1; //* |
oDone <= 0; |
oRAMWriteEnable <= 1; |
|
|
if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b0) |
NextState <= `TFU_REQUEST_NEXT_VERTEX_DIFFUSE; |
else if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b1) |
NextState <= `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE; |
else |
NextState <= `TFU_WAIT_FOR_VERTEX; |
end |
//------------------------------------ |
`TFU_REQUEST_NEXT_VERTEX_DIFFUSE: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 1; //* |
IncVertexCount <= 0; |
// oBusy <= 1; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
|
//if ( wVertexCount == 3) |
// NextState <= `TFU_REQUEST_DIFFUSE_COLOR; |
//else |
NextState <= `TFU_INC_WRITE_ADDRESS_DIFFUSE; |
end |
//------------------------------------ |
`TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 1; //* |
IncVertexCount <= 0; |
// oBusy <= 1; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
//$display("TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE, count = %d",wVertexCount); |
if ( wVertexCount == 6) |
NextState <= `TFU_REQUEST_DIFFUSE_COLOR; |
else |
NextState <= `TFU_REQUEST_VERTEX; |
end |
//------------------------------------ |
`TFU_INC_WRITE_ADDRESS_DIFFUSE: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 1; //* |
IncVertexCount <= 0; |
// oBusy <= 1; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
// $display(":) TFU_REQUEST_NEXT_VERTEX_DIFFUSE, count = %d",wVertexCount); |
if ( wVertexCount == 3) |
NextState <= `TFU_REQUEST_DIFFUSE_COLOR; |
else |
NextState <= `TFU_REQUEST_VERTEX; |
end |
//------------------------------------ |
`TFU_REQUEST_DIFFUSE_COLOR: |
begin |
|
// $display("TFU_REQUEST_DIFFUSE_COLOR: Writting to %d",oRAMWriteAddress); |
oTriggerWBM <= 1; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 1; |
oDone <= 0; |
oRAMWriteEnable <= 1; |
|
NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR; |
|
end |
//------------------------------------ |
`TFU_WAIT_FOR_DIFFUSE_COLOR: |
begin |
oTriggerWBM <= 1; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 1; |
oDone <= 0; //* |
oRAMWriteEnable <= 1; |
|
if ( iDataAvailable ) |
NextState <= `TFU_DONE; |
else |
NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR; |
|
end |
|
//------------------------------------ |
`TFU_DONE: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 0; //* |
oDone <= 1; //* |
oRAMWriteEnable <= 0; |
|
NextState <= `TFU_IDLE; |
end |
//------------------------------------ |
default: |
begin |
oTriggerWBM <= 0; |
oSetAddressWBM <= 0; |
IncWriteAddress <= 0; |
IncVertexCount <= 0; |
// oBusy <= 0; |
oDone <= 0; |
oRAMWriteEnable <= 0; |
|
NextState <= `TFU_IDLE; |
end |
//------------------------------------ |
endcase |
|
end //always |
endmodule |
//------------------------------------------------------------------------- |
/Unit_GEO.v
0,0 → 1,246
/********************************************************************************** |
Theaia, Ray Cast Programable graphic Processing Unit. |
Copyright (C) 2009 Diego Valverde (diego.valverde.g@gmail.com) |
|
This program is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License |
as published by the Free Software Foundation; either version 2 |
of the License, or (at your option) any later version. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
***********************************************************************************/ |
|
/********************************************************************************** |
Module Description: |
|
The scene geomtry is assumed to be grouped in a balance tree, specifically a |
OCT tree. |
Geometry unit is responsible for traversing this tree and requesting the geoemtry |
primitives accordingly. |
The root of the tree has global information on the scene, and each node |
can have up to 8 child nodes. Leafs can have geometry on it or not depending on the |
tree generation algorith. |
In the scenario where AABBIU is not used, the tree has a single node and a single leaf, |
which is the the root of the tree. |
The geomrty unit groups a series of modules that are in charge of fetching |
the various types of geometry. Depending on weather you are using AABBIU or not |
and wether you have texturing enabled or not, the way in which the primitives |
and data structures are requested varies. |
|
***********************************************************************************/ |
|
|
`timescale 1ns / 1ps |
`include "aDefinitions.v" |
|
`define GFSM_SELECT_TFU 2'b00 //Triangle Fetch |
`define GFSM_SELECT_TFF 2'b01 //Texture Fetch |
`define GFSM_SELECT_TNF 2'b10 //Tree node fetch |
`define GFSM_SELECT_NULL 2'b11 |
|
module GeometryUnit |
( |
|
input wire Clock, |
input wire Reset, |
input wire iEnable, |
input wire iTexturingEnable, |
input wire [`WIDTH-1:0] iData_WBM, |
input wire iDataReady_WBM, |
output wire [`WIDTH-1:0] oAddressWBM_Imm, |
output wire oAddressWBM_IsImm, |
output wire [`DATA_ADDRESS_WIDTH-1:0] oAddressWBM_fromMEM, |
output wire oEnable_WBM, |
output wire oSetAddressWBM, |
output wire oRequest_AABBIU, |
output wire oRequest_BIU, |
output wire oRequest_TCC, |
output wire[`DATA_ADDRESS_WIDTH-1:0] oRAMWriteAddress, |
output wire oRAMWriteEnable, |
input wire iMicrocodeExecutionDone, |
input wire iMicroCodeReturnValue, |
output wire oRequestingTextures, |
input wire iTrigger_TFF, |
input wire iBIUHit, |
output wire oTFFDone, |
output wire oSync, |
output wire oSetIOWriteBackAddr, |
input wire iIOBusy, |
|
`ifdef DEBUG |
input wire[`MAX_CORES-1:0] iDebug_CoreID, |
`endif |
output wire oDone |
); |
|
|
|
|
//Unit interconnections |
wire wTrigger_TNF; //Trigger Tree Node Fetch Unit. GSFM -> TNF |
wire wTrigger_TFU; //Trigger Data Fetch Unit. GFSM -> TFU |
//wire wTrigger_TFF; //Trigger testure Fetch Unit. GFSM -> TFF |
wire [`WIDTH-1:0] wNodeAddress; //Address of the current Node. GFSM -> TNF |
wire [`WIDTH-1:0] wTNF2_TFU__TriangleDataOffset; //Offset of the vertex Data. TNF -> GFSM |
wire [`WIDTH-1:0] wNode_TriangleCount; //Number of traingles in this node. TNF -> GFSM |
wire [`WIDTH-1:0] wNode_Brother_Address; //Address of the currents Node Brother. TNF -> GFSM |
wire [`WIDTH-1:0] wParents_Brother_Address; //Address of the Brother of current node's parent. TNF -> GFSM |
wire [`WIDTH-1:0] wAddress_TFU; |
//wire [`DATA_ADDRESS_WIDTH-1:0] wAddress_TFF; |
wire [`WIDTH-1:0] wAddress_TNF; |
wire [`DATA_ADDRESS_WIDTH-1:0] wRAMWriteAddress_TFU; |
wire [`DATA_ADDRESS_WIDTH-1:0] wRAMWriteAddress_TFF; |
wire [`DATA_ADDRESS_WIDTH-1:0] wRAMWriteAddress_TNF; |
wire [1:0] wWBM_Address_Selector; |
wire wTFN_Enable_WBM,wNode_IsLeaf; |
wire wTNF2__SetAddressWBM, wTFU2__SetAddressWBM,wTFF2__SetAddressWBM; |
wire wRAMWriteEnable_TFF; |
wire wNodeReadDone,wRAMWriteEnable_TNF,wTriangleReadDone,wTextureFetchDone; |
wire wTFU_Trigger_WBM,wTFF_Trigger_WBM,wRAMWriteEnable_TFU; |
wire wGFSM2_TFU__SetAddressOffset; |
|
assign oEnable_WBM = wTFN_Enable_WBM ^ wTFU_Trigger_WBM ^ wTFF_Trigger_WBM; //XXX TODO: Wath out! |
|
|
assign oRequestingTextures = (wWBM_Address_Selector == `GFSM_SELECT_TFF ) ? 1 : 0; |
assign oAddressWBM_Imm = ( wWBM_Address_Selector == `GFSM_SELECT_TFU ) ? wAddress_TFU : wAddress_TNF; |
assign oRAMWriteEnable = ( wWBM_Address_Selector == `GFSM_SELECT_TFU ) ? wRAMWriteEnable_TFU : wRAMWriteEnable_TNF; |
|
assign oAddressWBM_IsImm = |
( !iTexturingEnable || (iTexturingEnable && |
(wWBM_Address_Selector == `GFSM_SELECT_TFU || wWBM_Address_Selector == `GFSM_SELECT_TNF) )) |
? 1'b1 : 1'b0; |
|
//-------------------------------------------------------- |
//Mux for oRAMWriteAddress |
MUXFULLPARALELL_16bits_2SEL_X MUXGE_1B |
( |
.I1( wRAMWriteAddress_TFU ), |
.I2( wRAMWriteAddress_TFF ), |
.I3( wRAMWriteAddress_TNF ), |
.O1( oRAMWriteAddress ), |
.Sel( wWBM_Address_Selector ) |
); |
|
//-------------------------------------------------------- |
|
assign oSetAddressWBM = wTNF2__SetAddressWBM | wTFU2__SetAddressWBM | wTFF2__SetAddressWBM; |
|
|
//------------------------------------------------ |
|
/* |
Tree node fetcher: Takes care of resquesting |
node information. TNF requests Read Bus Cycles |
from the Wish Bone Master Unit. TNF is controlled |
by the GFSM. |
*/ |
TreeNodeFetcher TNF |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.iData( iData_WBM ), |
.iDataAvailable( iDataReady_WBM ), |
.oEnableWBM( wTFN_Enable_WBM ), |
.oSetAddressWBM( wTNF2__SetAddressWBM ), |
.oAddressWBM( wAddress_TNF ), |
.iInitialAddress( wNodeAddress ), |
.iTrigger( wTrigger_TNF ), |
.oNode_IsLeaf( wNode_IsLeaf ), |
.oNodeReadDone( wNodeReadDone ), |
.oNode_TriangleCount( wNode_TriangleCount ), |
.oNode_Brother_Address( wNode_Brother_Address ), |
.oParents_Brother_Address( wParents_Brother_Address ), |
.oNode_DataOffset( wTNF2_TFU__TriangleDataOffset ), |
.oRAMWriteEnable( wRAMWriteEnable_TNF ), |
`ifdef DEBUG |
.iDebug_CoreID( iDebug_CoreID ), |
`endif |
.oRAMWriteAddress( wRAMWriteAddress_TNF ) |
|
); |
//------------------------------------------------ |
/* |
Triangle Fetch Unit: Takes care of resquesting |
triangle information. TFU requests Read Bus Cycles |
from the Wish Bone Master Unit. TFU is controlled |
by the GFSM. |
*/ |
TriangleFetchUnit TFU |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.iTrigger( wTrigger_TFU ), |
.iInitialAddress( wTNF2_TFU__TriangleDataOffset ), |
.iSetAddressOffset( wGFSM2_TFU__SetAddressOffset ), |
.iDataAvailable( iDataReady_WBM ), |
.oAddressWBM( wAddress_TFU ), |
.oSetAddressWBM( wTFU2__SetAddressWBM ), |
.oTriggerWBM( wTFU_Trigger_WBM ), |
.oRAMWriteEnable( wRAMWriteEnable_TFU ), |
.iCR_TextureMappingEnabled( iTexturingEnable ), |
.oRAMWriteAddress( wRAMWriteAddress_TFU ), |
`ifdef DEBUG |
.iDebug_CoreID( iDebug_CoreID ), |
`endif |
.oDone( wTriangleReadDone ) |
); |
|
//------------------------------------------------ |
/* |
Geometry Fetch Finite State Machine: Takes care of resquesting |
the control of the various geometry fetching routines. It controls |
TFF,TFU and TNF. |
*/ |
GeometryFetchFSM GFSM //TODO: Add new states to fetch the texures |
( |
.Clock( Clock ), |
.Reset( Reset ), |
.iBIUHit( iBIUHit ), |
.iIOBusy( iIOBusy ), |
.iTexturingEnable( iTexturingEnable ), |
.iEnable( iEnable ), |
.iAABBIUHit( iMicroCodeReturnValue ), |
.iUCodeDone( iMicrocodeExecutionDone ), |
.iTriangleReadDone( wTriangleReadDone ), |
.iNode_TriangleCount( wNode_TriangleCount ), |
.iNode_Brother_Address( wNode_Brother_Address ), |
.iNode_Parents_Brother_Address( wParents_Brother_Address ), |
.iNode_IsLeaf( wNode_IsLeaf ), |
.iNodeReadDone( wNodeReadDone ), |
.oTrigger_TNF( wTrigger_TNF ), |
.oTrigger_TFU( wTrigger_TFU ), |
.oNodeAddress( wNodeAddress ), |
.oRequest_AABBIU( oRequest_AABBIU ), |
.oRequest_BIU( oRequest_BIU ), |
.oRequest_TCC( oRequest_TCC ), |
.oWBM_Addr_Selector( wWBM_Address_Selector ), |
.oSync( oSync ), |
.oSetTFUAddressOffset( wGFSM2_TFU__SetAddressOffset ), |
.oDone( oDone ), |
.iDataAvailable( iDataReady_WBM ), |
.oEnable_WBM( wTFF_Trigger_WBM ), |
.oAddressWBM( oAddressWBM_fromMEM ), |
.oSetAddressWBM( wTFF2__SetAddressWBM ), |
.iTrigger_TFF( iTrigger_TFF ), |
.oSetIOWriteBackAddr( oSetIOWriteBackAddr ), |
`ifdef DEBUG |
.iDebug_CoreID( iDebug_CoreID ), |
`endif |
.oRAMTextureStoreLocation( wRAMWriteAddress_TFF ) |
|
); |
assign oTFFDone = oDone; |
|
//------------------------------------------------- |
|
|
endmodule |