//=======================================================================
|
//=======================================================================
|
// Project Monophony
|
// Project Monophony
|
// Wire-Frame 3D Graphics Accelerator IP Core
|
// Wire-Frame 3D Graphics Accelerator IP Core
|
//
|
//
|
// File:
|
// File:
|
// fm_ras_state.v
|
// fm_ras_state.v
|
//
|
//
|
// Abstract:
|
// Abstract:
|
// line distribution
|
// line distribution
|
// line is rejected when:
|
// line is rejected when:
|
// both vertices are outside +-X, or +-Y plane
|
// both vertices are outside +-X, or +-Y plane
|
//
|
//
|
// Author:
|
// Author:
|
// Kenji Ishimaru (info.wf3d@gmail.com)
|
// Kenji Ishimaru (info.info.wf3d@gmail.com)
|
//
|
//
|
//======================================================================
|
//======================================================================
|
//
|
//
|
// Copyright (c) 2015, Kenji Ishimaru
|
// Copyright (c) 2015, Kenji Ishimaru
|
// All rights reserved.
|
// All rights reserved.
|
//
|
//
|
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
// modification, are permitted provided that the following conditions are met:
|
// modification, are permitted provided that the following conditions are met:
|
//
|
//
|
// -Redistributions of source code must retain the above copyright notice,
|
// -Redistributions of source code must retain the above copyright notice,
|
// this list of conditions and the following disclaimer.
|
// this list of conditions and the following disclaimer.
|
// -Redistributions in binary form must reproduce the above copyright notice,
|
// -Redistributions in binary form must reproduce the above copyright notice,
|
// this list of conditions and the following disclaimer in the documentation
|
// this list of conditions and the following disclaimer in the documentation
|
// and/or other materials provided with the distribution.
|
// and/or other materials provided with the distribution.
|
//
|
//
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
//
|
//
|
// Revision History
|
// Revision History
|
|
|
`include "fm_3d_define.v"
|
`include "fm_3d_define.v"
|
module fm_ras_state (
|
module fm_ras_state (
|
// system
|
// system
|
input clk_core,
|
input clk_core,
|
input rst_x,
|
input rst_x,
|
// Register Configuration
|
// Register Configuration
|
input [15:0] i_scr_w_m1, // Screen Width-1
|
input [15:0] i_scr_w_m1, // Screen Width-1
|
input [15:0] i_scr_h_m1, // Screen Height-1
|
input [15:0] i_scr_h_m1, // Screen Height-1
|
// Vertex input
|
// Vertex input
|
input i_en,
|
input i_en,
|
output o_ack,
|
output o_ack,
|
input [`D3D_FTOI_WIDTH-1:0] i_v0_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v0_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v0_y,
|
input [`D3D_FTOI_WIDTH-1:0] i_v0_y,
|
input [`D3D_FTOI_WIDTH-1:0] i_v1_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v1_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v1_y,
|
input [`D3D_FTOI_WIDTH-1:0] i_v1_y,
|
input [`D3D_FTOI_WIDTH-1:0] i_v2_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v2_x,
|
input [`D3D_FTOI_WIDTH-1:0] i_v2_y,
|
input [`D3D_FTOI_WIDTH-1:0] i_v2_y,
|
output o_ras_state,
|
output o_ras_state,
|
// Current Line
|
// Current Line
|
output o_en,
|
output o_en,
|
input i_ack,
|
input i_ack,
|
output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
|
output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
|
output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
|
output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
|
output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
|
output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
|
output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
|
output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
|
input i_state
|
input i_state
|
);
|
);
|
|
|
localparam P_IDLE = 'd0;
|
localparam P_IDLE = 'd0;
|
localparam P_LINE_0 = 'd1;
|
localparam P_LINE_0 = 'd1;
|
localparam P_LINE_1 = 'd2;
|
localparam P_LINE_1 = 'd2;
|
localparam P_LINE_2 = 'd3;
|
localparam P_LINE_2 = 'd3;
|
|
|
//////////////////////////////////
|
//////////////////////////////////
|
// reg
|
// reg
|
//////////////////////////////////
|
//////////////////////////////////
|
reg [2:0] r_state;
|
reg [2:0] r_state;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v0_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v0_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v0_y;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v0_y;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v1_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v1_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v1_y;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v1_y;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v2_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v2_x;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v2_y;
|
reg [`D3D_FTOI_WIDTH-1:0] r_v2_y;
|
//////////////////////////////////
|
//////////////////////////////////
|
// wire
|
// wire
|
//////////////////////////////////
|
//////////////////////////////////
|
wire w_set_vtx;
|
wire w_set_vtx;
|
wire w_reject_l0;
|
wire w_reject_l0;
|
wire w_reject_l1;
|
wire w_reject_l1;
|
wire w_reject_l2;
|
wire w_reject_l2;
|
//////////////////////////////////
|
//////////////////////////////////
|
// assign
|
// assign
|
//////////////////////////////////
|
//////////////////////////////////
|
assign o_en = ((r_state == P_LINE_0) & ~w_reject_l0) |
|
assign o_en = ((r_state == P_LINE_0) & ~w_reject_l0) |
|
((r_state == P_LINE_1) & ~w_reject_l1) |
|
((r_state == P_LINE_1) & ~w_reject_l1) |
|
((r_state == P_LINE_2) & ~w_reject_l2);
|
((r_state == P_LINE_2) & ~w_reject_l2);
|
assign o_ack = (r_state == P_IDLE);
|
assign o_ack = (r_state == P_IDLE);
|
|
|
// LINE 0: v0,v1
|
// LINE 0: v0,v1
|
// LINE 1: v1,v2
|
// LINE 1: v1,v2
|
// LINE 2: v2,v0
|
// LINE 2: v2,v0
|
|
|
assign o_v0_x = (r_state == P_LINE_0) ? r_v0_x :
|
assign o_v0_x = (r_state == P_LINE_0) ? r_v0_x :
|
(r_state == P_LINE_1) ? r_v1_x : r_v2_x;
|
(r_state == P_LINE_1) ? r_v1_x : r_v2_x;
|
assign o_v0_y = (r_state == P_LINE_0) ? r_v0_y :
|
assign o_v0_y = (r_state == P_LINE_0) ? r_v0_y :
|
(r_state == P_LINE_1) ? r_v1_y : r_v2_y;
|
(r_state == P_LINE_1) ? r_v1_y : r_v2_y;
|
assign o_v1_x = (r_state == P_LINE_0) ? r_v1_x :
|
assign o_v1_x = (r_state == P_LINE_0) ? r_v1_x :
|
(r_state == P_LINE_1) ? r_v2_x : r_v0_x;
|
(r_state == P_LINE_1) ? r_v2_x : r_v0_x;
|
assign o_v1_y = (r_state == P_LINE_0) ? r_v1_y :
|
assign o_v1_y = (r_state == P_LINE_0) ? r_v1_y :
|
(r_state == P_LINE_1) ? r_v2_y : r_v0_y;
|
(r_state == P_LINE_1) ? r_v2_y : r_v0_y;
|
|
|
assign w_set_vtx = (r_state == P_IDLE) & i_en;
|
assign w_set_vtx = (r_state == P_IDLE) & i_en;
|
assign o_ras_state = (r_state == P_IDLE) & i_state;
|
assign o_ras_state = (r_state == P_IDLE) & i_state;
|
|
|
assign w_reject_l0 = f_reject(r_v0_x,r_v0_y,r_v1_x,r_v1_y,i_scr_w_m1,i_scr_h_m1);
|
assign w_reject_l0 = f_reject(r_v0_x,r_v0_y,r_v1_x,r_v1_y,i_scr_w_m1,i_scr_h_m1);
|
assign w_reject_l1 = f_reject(r_v1_x,r_v1_y,r_v2_x,r_v2_y,i_scr_w_m1,i_scr_h_m1);
|
assign w_reject_l1 = f_reject(r_v1_x,r_v1_y,r_v2_x,r_v2_y,i_scr_w_m1,i_scr_h_m1);
|
assign w_reject_l2 = f_reject(r_v2_x,r_v2_y,r_v0_x,r_v0_y,i_scr_w_m1,i_scr_h_m1);
|
assign w_reject_l2 = f_reject(r_v2_x,r_v2_y,r_v0_x,r_v0_y,i_scr_w_m1,i_scr_h_m1);
|
//////////////////////////////////
|
//////////////////////////////////
|
// always
|
// always
|
//////////////////////////////////
|
//////////////////////////////////
|
|
|
always @(posedge clk_core) begin
|
always @(posedge clk_core) begin
|
if (w_set_vtx) begin
|
if (w_set_vtx) begin
|
r_v0_x <= i_v0_x;
|
r_v0_x <= i_v0_x;
|
r_v0_y <= i_v0_y;
|
r_v0_y <= i_v0_y;
|
r_v1_x <= i_v1_x;
|
r_v1_x <= i_v1_x;
|
r_v1_y <= i_v1_y;
|
r_v1_y <= i_v1_y;
|
r_v2_x <= i_v2_x;
|
r_v2_x <= i_v2_x;
|
r_v2_y <= i_v2_y;
|
r_v2_y <= i_v2_y;
|
end
|
end
|
end
|
end
|
|
|
`ifdef D3D_SYNC_RESET
|
`ifdef D3D_SYNC_RESET
|
always @(posedge clk_core) begin
|
always @(posedge clk_core) begin
|
`else
|
`else
|
always @(posedge clk_core or negedge rst_x) begin
|
always @(posedge clk_core or negedge rst_x) begin
|
`endif
|
`endif
|
if (rst_x == `D3D_RESET_POL) begin
|
if (rst_x == `D3D_RESET_POL) begin
|
r_state <= P_IDLE;
|
r_state <= P_IDLE;
|
end else begin
|
end else begin
|
case (r_state)
|
case (r_state)
|
P_IDLE: begin
|
P_IDLE: begin
|
if (i_en) r_state <= P_LINE_0;
|
if (i_en) r_state <= P_LINE_0;
|
end
|
end
|
P_LINE_0: begin
|
P_LINE_0: begin
|
if (i_ack | w_reject_l0) r_state <= P_LINE_1;
|
if (i_ack | w_reject_l0) r_state <= P_LINE_1;
|
end
|
end
|
P_LINE_1: begin
|
P_LINE_1: begin
|
if (i_ack | w_reject_l1) r_state <= P_LINE_2;
|
if (i_ack | w_reject_l1) r_state <= P_LINE_2;
|
end
|
end
|
P_LINE_2: begin
|
P_LINE_2: begin
|
if (i_ack | w_reject_l2) r_state <= P_IDLE;
|
if (i_ack | w_reject_l2) r_state <= P_IDLE;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
|
|
function f_reject;
|
function f_reject;
|
input [`D3D_FTOI_WIDTH-1:0] v0_x;
|
input [`D3D_FTOI_WIDTH-1:0] v0_x;
|
input [`D3D_FTOI_WIDTH-1:0] v0_y;
|
input [`D3D_FTOI_WIDTH-1:0] v0_y;
|
input [`D3D_FTOI_WIDTH-1:0] v1_x;
|
input [`D3D_FTOI_WIDTH-1:0] v1_x;
|
input [`D3D_FTOI_WIDTH-1:0] v1_y;
|
input [`D3D_FTOI_WIDTH-1:0] v1_y;
|
input [15:0] scr_w;
|
input [15:0] scr_w;
|
input [15:0] scr_h;
|
input [15:0] scr_h;
|
reg result;
|
reg result;
|
begin
|
begin
|
result = 1'b0;
|
result = 1'b0;
|
if (v0_x[`D3D_FTOI_WIDTH-1] & v1_x[`D3D_FTOI_WIDTH-1]) result = 1'b1; // negative
|
if (v0_x[`D3D_FTOI_WIDTH-1] & v1_x[`D3D_FTOI_WIDTH-1]) result = 1'b1; // negative
|
if (v0_y[`D3D_FTOI_WIDTH-1] & v1_y[`D3D_FTOI_WIDTH-1]) result = 1'b1;
|
if (v0_y[`D3D_FTOI_WIDTH-1] & v1_y[`D3D_FTOI_WIDTH-1]) result = 1'b1;
|
if ((~v0_x[`D3D_FTOI_WIDTH-1] & (v0_x[`D3D_FTOI_WIDTH-2:0] > scr_w))&
|
if ((~v0_x[`D3D_FTOI_WIDTH-1] & (v0_x[`D3D_FTOI_WIDTH-2:0] > scr_w))&
|
(~v1_x[`D3D_FTOI_WIDTH-1] & (v1_x[`D3D_FTOI_WIDTH-2:0] > scr_w))) result = 1'b1;
|
(~v1_x[`D3D_FTOI_WIDTH-1] & (v1_x[`D3D_FTOI_WIDTH-2:0] > scr_w))) result = 1'b1;
|
if ((~v0_y[`D3D_FTOI_WIDTH-1] & (v0_y[`D3D_FTOI_WIDTH-2:0] > scr_h))&
|
if ((~v0_y[`D3D_FTOI_WIDTH-1] & (v0_y[`D3D_FTOI_WIDTH-2:0] > scr_h))&
|
(~v1_y[`D3D_FTOI_WIDTH-1] & (v1_y[`D3D_FTOI_WIDTH-2:0] > scr_h))) result = 1'b1;
|
(~v1_y[`D3D_FTOI_WIDTH-1] & (v1_y[`D3D_FTOI_WIDTH-2:0] > scr_h))) result = 1'b1;
|
f_reject = result;
|
f_reject = result;
|
end
|
end
|
endfunction
|
endfunction
|
|
|
endmodule
|
endmodule
|
|
|