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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [tags/] [Beta_0.2/] [rtl/] [GEO/] [Module_TriangleFetch.v] - Diff between revs 82 and 86

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 82 Rev 86
`timescale 1ns / 1ps
`timescale 1ns / 1ps
`include "aDefinitions.v"
`include "aDefinitions.v"
 
 
`define TFU_AFTER_RESET                                                                 0
`define TFU_AFTER_RESET                                                                 0
`define TFU_IDLE                                                                                        1
`define TFU_IDLE                                                                                        1
`define TFU_REQUEST_VERTEX                                                              2
`define TFU_REQUEST_VERTEX                                                              2
`define TFU_WAIT_FOR_VERTEX                                                     3
`define TFU_WAIT_FOR_VERTEX                                                     3
`define TFU_REQUEST_NEXT_VERTEX_DIFFUSE                 4
`define TFU_REQUEST_NEXT_VERTEX_DIFFUSE                 4
`define TFU_REQUEST_DIFFUSE_COLOR                                       5
`define TFU_REQUEST_DIFFUSE_COLOR                                       5
`define TFU_WAIT_FOR_DIFFUSE_COLOR                                      6
`define TFU_WAIT_FOR_DIFFUSE_COLOR                                      6
`define TFU_SET_WBM_INITIAL_ADDRESS                             7
`define TFU_SET_WBM_INITIAL_ADDRESS                             7
`define TFU_CHECK_FOR_WBM_ADDRESS_SET                           8
`define TFU_CHECK_FOR_WBM_ADDRESS_SET                           8
`define TFU_SET_DIFFUSE_COLOR_ADDRESS                           9
`define TFU_SET_DIFFUSE_COLOR_ADDRESS                           9
`define TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE              10
`define TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE              10
`define TFU_INC_WRITE_ADDRESS_DIFFUSE                           11
`define TFU_INC_WRITE_ADDRESS_DIFFUSE                           11
`define TFU_DONE                                                                                        12
`define TFU_DONE                                                                                        12
/**********************************************************************************
/**********************************************************************************
Theia, Ray Cast Programable graphic Processing Unit.
Theia, Ray Cast Programable graphic Processing Unit.
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
 
 
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
of the License, or (at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
***********************************************************************************/
***********************************************************************************/
/*
/*
 
 
 
 
        Warning: setting iTrigger while oBusy = 1 will reset the Up counters!
        Warning: setting iTrigger while oBusy = 1 will reset the Up counters!
 
 
*/
*/
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
module TriangleFetchUnit
module TriangleFetchUnit
(
(
        input wire                                      Clock,
        input wire                                      Clock,
        input wire                                      Reset,
        input wire                                      Reset,
        input   wire                                    iTrigger,
        input   wire                                    iTrigger,
        //output reg                                    oBusy,                                                  //I am currently busy
        //output reg                                    oBusy,                                                  //I am currently busy
        output reg                                      oDone,                                                  //Done reading trinagle data
        output reg                                      oDone,                                                  //Done reading trinagle data
        //Wires from GFSM
        //Wires from GFSM
        input   wire                                    iDataAvailable,                         //Data is ready
        input   wire                                    iDataAvailable,                         //Data is ready
        input wire[`WIDTH-1:0]   iInitialAddress,                                //The initial address of the data
        input wire[`WIDTH-1:0]   iInitialAddress,                                //The initial address of the data
        input wire                                      iSetAddressOffset,                      //Set the iInitialAddress Now
        input wire                                      iSetAddressOffset,                      //Set the iInitialAddress Now
        //Wires from Control Register
        //Wires from Control Register
        input wire                                      iCR_TextureMappingEnabled,      //Is the texture map fearure enable?
        input wire                                      iCR_TextureMappingEnabled,      //Is the texture map fearure enable?
 
 
        //Wires to WBM
        //Wires to WBM
        output reg                                                                              oTriggerWBM,
        output reg                                                                              oTriggerWBM,
        output wire[`WIDTH-1:0]                                          oAddressWBM,
        output wire[`WIDTH-1:0]                                          oAddressWBM,
        output reg                                                                              oSetAddressWBM,
        output reg                                                                              oSetAddressWBM,
        output wire[`DATA_ADDRESS_WIDTH-1:0]     oRAMWriteAddress,
        output wire[`DATA_ADDRESS_WIDTH-1:0]     oRAMWriteAddress,
        `ifdef DEBUG
        `ifdef DEBUG
        input wire[`MAX_CORES-1:0]            iDebug_CoreID,
        input wire[`MAX_CORES-1:0]            iDebug_CoreID,
        `endif
        `endif
        output reg                                                                              oRAMWriteEnable
        output reg                                                                              oRAMWriteEnable
 
 
);
);
 
 
 
 
 
 
assign oAddressWBM = iInitialAddress;///Must change or will always read first triangle in the list....
assign oAddressWBM = iInitialAddress;///Must change or will always read first triangle in the list....
 
 
 
 
reg [4:0]        CurrentState,NextState;
reg [4:0]        CurrentState,NextState;
reg IncWriteAddress,IncVertexCount;
reg IncWriteAddress,IncVertexCount;
wire [2:0] wVertexCount;
wire [2:0] wVertexCount;
//-----------------------------
//-----------------------------
UpCounter_3 TNF_VC1
UpCounter_3 TNF_VC1
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( iTrigger ),
.Reset( iTrigger ),
.Initial( 3'b0 ),
.Initial( 3'b0 ),
.Enable( IncVertexCount ),
.Enable( IncVertexCount ),
.Q( wVertexCount )
.Q( wVertexCount )
);
);
 
 
 
 
//-----------------------------
//-----------------------------
UpCounter_16E TNF_TFU_2
UpCounter_16E TNF_TFU_2
(
(
 
 
.Clock( Clock ),
.Clock( Clock ),
.Reset( iTrigger ),
.Reset( iTrigger ),
.Initial( `CREG_V0 ),//iRAMWriteOffset ),
.Initial( `CREG_V0 ),//iRAMWriteOffset ),
.Enable( IncWriteAddress ),
.Enable( IncWriteAddress ),
.Q( oRAMWriteAddress )
.Q( oRAMWriteAddress )
 
 
);
);
 
 
//------------------------------------------------
//------------------------------------------------
  always @(posedge Clock or posedge Reset)
  always @(posedge Clock or posedge Reset)
  begin
  begin
 
 
    if (Reset)
    if (Reset)
                CurrentState <= `TFU_AFTER_RESET;
                CurrentState <= `TFU_AFTER_RESET;
    else
    else
                CurrentState <= NextState;
                CurrentState <= NextState;
 
 
  end
  end
 
 
//------------------------------------
//------------------------------------
always @( * )
always @( * )
   begin
   begin
   case (CurrentState)
   case (CurrentState)
        //------------------------------------
        //------------------------------------
        `TFU_AFTER_RESET:
        `TFU_AFTER_RESET:
        begin
        begin
 
 
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 0;
        //      oBusy                                   <= 0;
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                NextState <= `TFU_IDLE;
                NextState <= `TFU_IDLE;
   end
   end
        //------------------------------------
        //------------------------------------
        `TFU_IDLE:
        `TFU_IDLE:
        begin
        begin
 
 
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 0;
        //      oBusy                                   <= 0;
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                if ( iTrigger )
                if ( iTrigger )
                        NextState <= `TFU_CHECK_FOR_WBM_ADDRESS_SET;
                        NextState <= `TFU_CHECK_FOR_WBM_ADDRESS_SET;
                else
                else
                        NextState <= `TFU_IDLE;
                        NextState <= `TFU_IDLE;
 
 
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_CHECK_FOR_WBM_ADDRESS_SET:
        `TFU_CHECK_FOR_WBM_ADDRESS_SET:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 0;
        //      oBusy                                   <= 0;
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                if ( iSetAddressOffset )
                if ( iSetAddressOffset )
                        NextState <= `TFU_SET_WBM_INITIAL_ADDRESS;
                        NextState <= `TFU_SET_WBM_INITIAL_ADDRESS;
                else
                else
                        NextState <= `TFU_REQUEST_VERTEX;
                        NextState <= `TFU_REQUEST_VERTEX;
 
 
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_SET_WBM_INITIAL_ADDRESS:
        `TFU_SET_WBM_INITIAL_ADDRESS:
        begin
        begin
 
 
                `ifdef DEBUG
                `ifdef DEBUG
                        $display("TFU: TFU_SET_WBM_INITIAL_ADDRESS");
                        $display("TFU: TFU_SET_WBM_INITIAL_ADDRESS");
                `endif
                `endif
 
 
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 1; //*
                oSetAddressWBM          <= 1; //*
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; //*
        //      oBusy                                   <= 1; //*
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                NextState <= `TFU_REQUEST_VERTEX;
                NextState <= `TFU_REQUEST_VERTEX;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_REQUEST_VERTEX:
        `TFU_REQUEST_VERTEX:
        begin
        begin
                oTriggerWBM                     <= 1; //*
                oTriggerWBM                     <= 1; //*
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 1; //*
                IncVertexCount          <= 1; //*
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 1; //*
                oRAMWriteEnable <= 1; //*
                //$display("TFU_REQUEST_VERTEX %d to wirte to %d\n",oAddressWBM,oRAMWriteAddress);
                //$display("TFU_REQUEST_VERTEX %d to wirte to %d\n",oAddressWBM,oRAMWriteAddress);
                NextState <= `TFU_WAIT_FOR_VERTEX;
                NextState <= `TFU_WAIT_FOR_VERTEX;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_WAIT_FOR_VERTEX:
        `TFU_WAIT_FOR_VERTEX:
        begin
        begin
 
 
                oTriggerWBM                     <= 1;
                oTriggerWBM                     <= 1;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; //*
        //      oBusy                                   <= 1; //*
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 1;
                oRAMWriteEnable <= 1;
 
 
 
 
                if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b0)
                if ( iDataAvailable && iCR_TextureMappingEnabled == 1'b0)
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_DIFFUSE;
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_DIFFUSE;
                else if ( iDataAvailable &&     iCR_TextureMappingEnabled == 1'b1)
                else if ( iDataAvailable &&     iCR_TextureMappingEnabled == 1'b1)
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE;
                        NextState <= `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE;
                else
                else
                        NextState <= `TFU_WAIT_FOR_VERTEX;
                        NextState <= `TFU_WAIT_FOR_VERTEX;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_REQUEST_NEXT_VERTEX_DIFFUSE:
        `TFU_REQUEST_NEXT_VERTEX_DIFFUSE:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 1; //*
                IncWriteAddress         <= 1; //*
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
 
 
                //if ( wVertexCount == 3)
                //if ( wVertexCount == 3)
                //      NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                //      NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                //else
                //else
                        NextState <= `TFU_INC_WRITE_ADDRESS_DIFFUSE;
                        NextState <= `TFU_INC_WRITE_ADDRESS_DIFFUSE;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE:
        `TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 1; //*
                IncWriteAddress         <= 1; //*
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                //$display("TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE, count = %d",wVertexCount);
                //$display("TFU_REQUEST_NEXT_VERTEX_UV_DIFFUSE, count = %d",wVertexCount);
                if ( wVertexCount == 6)
                if ( wVertexCount == 6)
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                else
                else
                        NextState <= `TFU_REQUEST_VERTEX;
                        NextState <= `TFU_REQUEST_VERTEX;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_INC_WRITE_ADDRESS_DIFFUSE:
        `TFU_INC_WRITE_ADDRESS_DIFFUSE:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 1; //*
                IncWriteAddress         <= 1; //*
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
        //      $display(":) TFU_REQUEST_NEXT_VERTEX_DIFFUSE, count = %d",wVertexCount);
        //      $display(":) TFU_REQUEST_NEXT_VERTEX_DIFFUSE, count = %d",wVertexCount);
                if ( wVertexCount == 3)
                if ( wVertexCount == 3)
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                        NextState <= `TFU_REQUEST_DIFFUSE_COLOR;
                else
                else
                        NextState <= `TFU_REQUEST_VERTEX;
                        NextState <= `TFU_REQUEST_VERTEX;
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_REQUEST_DIFFUSE_COLOR:
        `TFU_REQUEST_DIFFUSE_COLOR:
        begin
        begin
 
 
//              $display("TFU_REQUEST_DIFFUSE_COLOR: Writting to %d",oRAMWriteAddress);
//              $display("TFU_REQUEST_DIFFUSE_COLOR: Writting to %d",oRAMWriteAddress);
                oTriggerWBM                     <= 1;
                oTriggerWBM                     <= 1;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 1;
                oRAMWriteEnable <= 1;
 
 
                NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
                NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
 
 
        end
        end
        //------------------------------------
        //------------------------------------
        `TFU_WAIT_FOR_DIFFUSE_COLOR:
        `TFU_WAIT_FOR_DIFFUSE_COLOR:
        begin
        begin
                oTriggerWBM                     <= 1;
                oTriggerWBM                     <= 1;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 1; 
        //      oBusy                                   <= 1; 
                oDone                                   <= 0; //*
                oDone                                   <= 0; //*
                oRAMWriteEnable <= 1;
                oRAMWriteEnable <= 1;
 
 
                if ( iDataAvailable )
                if ( iDataAvailable )
                        NextState <= `TFU_DONE;
                        NextState <= `TFU_DONE;
                else
                else
                        NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
                        NextState <= `TFU_WAIT_FOR_DIFFUSE_COLOR;
 
 
        end
        end
 
 
        //------------------------------------
        //------------------------------------
        `TFU_DONE:
        `TFU_DONE:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 0;   //*
        //      oBusy                                   <= 0;   //*
                oDone                                   <= 1; //*
                oDone                                   <= 1; //*
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                NextState <= `TFU_IDLE;
                NextState <= `TFU_IDLE;
        end
        end
        //------------------------------------
        //------------------------------------
        default:
        default:
        begin
        begin
                oTriggerWBM                     <= 0;
                oTriggerWBM                     <= 0;
                oSetAddressWBM          <= 0;
                oSetAddressWBM          <= 0;
                IncWriteAddress         <= 0;
                IncWriteAddress         <= 0;
                IncVertexCount          <= 0;
                IncVertexCount          <= 0;
        //      oBusy                                   <= 0;
        //      oBusy                                   <= 0;
                oDone                                   <= 0;
                oDone                                   <= 0;
                oRAMWriteEnable <= 0;
                oRAMWriteEnable <= 0;
 
 
                NextState <= `TFU_IDLE;
                NextState <= `TFU_IDLE;
        end
        end
        //------------------------------------
        //------------------------------------
        endcase
        endcase
 
 
end //always
end //always
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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