bilinear fixes + refactoring

This commit is contained in:
Blaise Tine
2021-03-31 23:30:36 -04:00
parent 99ca04ce8c
commit fa2d84831e
7 changed files with 106 additions and 223 deletions

View File

@@ -1,68 +0,0 @@
`include "VX_tex_define.vh"
module VX_tex_bilerp #(
parameter CORE_ID = 0
) (
input wire [`BLEND_FRAC_64-1:0] blendU,
input wire [`BLEND_FRAC_64-1:0] blendV,
input wire [3:0][63:0] texels,
input wire [`NUM_COLOR_CHANNEL-1:0] color_enable,
output wire [31:0] sampled_data
);
`UNUSED_PARAM (CORE_ID)
wire [63:0] UL_lerp;
wire [63:0] UH_lerp;
wire [63:0] V_lerp;
reg [31:0] sampled_r;
VX_tex_lerp #(
) tex_lerp_UL (
.blend(blendU),
.in_texels({texels[1], texels[0]}),
.lerp_texel(UL_lerp)
);
VX_tex_lerp #(
) tex_lerp_UH (
.blend(blendU),
.in_texels({texels[3], texels[2]}),
.lerp_texel(UH_lerp)
);
VX_tex_lerp #(
) tex_lerp_V (
.blend(blendV),
.in_texels({UH_lerp, UL_lerp}),
.lerp_texel(V_lerp)
);
`UNUSED_VAR (V_lerp[63:56])
always @(*) begin
if (color_enable[3]==1'b1) //R
sampled_r[31:24] = V_lerp[55:48];
else
sampled_r[31:24] = {`TEX_COLOR_BITS{1'b0}};
if (color_enable[2]==1'b1) //G
sampled_r[23:16] = V_lerp[39:32];
else
sampled_r[23:16] = {`TEX_COLOR_BITS{1'b0}};
if (color_enable[1]==1'b1) //B
sampled_r[15:8] = V_lerp[23:16];
else
sampled_r[15:8] = {`TEX_COLOR_BITS{1'b0}};
if (color_enable[0]==1'b1) //A
sampled_r[7:0] = V_lerp[7:0];
else
sampled_r[7:0] = {`TEX_COLOR_BITS{1'b1}};
end
assign sampled_data = sampled_r;
endmodule

View File

@@ -11,10 +11,6 @@
`define CLAMP(x,lo,hi) (($signed(x) < $signed(lo)) ? lo : ((x > hi) ? hi : x)) `define CLAMP(x,lo,hi) (($signed(x) < $signed(lo)) ? lo : ((x > hi) ? hi : x))
`define BLEND_FRAC_64 8
`define LERP_64(x1,x2,frac) ((x2 + (((x1 - x2) * frac) >> `BLEND_FRAC_64)) & 64'h00ff00ff00ff00ff)
`define TEX_ADDR_BITS 32 `define TEX_ADDR_BITS 32
`define TEX_FORMAT_BITS 3 `define TEX_FORMAT_BITS 3
`define TEX_WRAP_BITS 2 `define TEX_WRAP_BITS 2
@@ -32,10 +28,8 @@
`define TEX_WRAP_REPEAT 1 `define TEX_WRAP_REPEAT 1
`define TEX_WRAP_MIRROR 2 `define TEX_WRAP_MIRROR 2
`define MAX_COLOR_WIDTH 8
`define NUM_COLOR_CHANNEL 4
`define TEX_COLOR_BITS 8 `define TEX_COLOR_BITS 8
`define BLEND_FRAC 8
`define TEX_FORMAT_R8G8B8A8 `TEX_FORMAT_BITS'(0) `define TEX_FORMAT_R8G8B8A8 `TEX_FORMAT_BITS'(0)
`define TEX_FORMAT_R5G6B5 `TEX_FORMAT_BITS'(1) `define TEX_FORMAT_R5G6B5 `TEX_FORMAT_BITS'(1)

View File

@@ -1,125 +1,57 @@
`include "VX_tex_define.vh" `include "VX_tex_define.vh"
module VX_tex_format #( module VX_tex_format #(
parameter CORE_ID = 0, parameter CORE_ID = 0
parameter NUM_TEXELS = 4 //BILINEAR
) ( ) (
input wire [NUM_TEXELS-1:0][31:0] texel_data, input wire [`TEX_FORMAT_BITS-1:0] format,
input wire [`TEX_FORMAT_BITS-1:0] format, input wire [31:0] texel_in,
output wire [31:0] texel_out
output wire [`NUM_COLOR_CHANNEL-1:0] color_enable,
output wire [NUM_TEXELS-1:0][63:0] formatted_lerp_texel,
output wire [31:0] formatted_pt_texel
); );
`UNUSED_PARAM (CORE_ID) `UNUSED_PARAM (CORE_ID)
reg [`NUM_COLOR_CHANNEL-1:0] color_enable_r; reg [31:0] texel_out_r;
reg [NUM_TEXELS-1:0][63:0] formatted_texel_r;
reg [31:0] formatted_pt_r;
always @(*) begin always @(*) begin
// bilerp/trilerp input
for (integer i = 0; i<NUM_TEXELS ;i++ ) begin
case (format)
`TEX_FORMAT_R5G6B5: begin
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][4:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(texel_data[i][10:5]);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(texel_data[i][15:11]);
formatted_texel_r[i][55:48] = {`TEX_COLOR_BITS{1'b0}};
if (i == 0)
color_enable_r = 4'b0111;
end
`TEX_FORMAT_R4G4B4A4: begin
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][3:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(texel_data[i][7:4]);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(texel_data[i][11:8]);
formatted_texel_r[i][55:48] = `TEX_COLOR_BITS'(texel_data[i][15:12]);
if (i == 0)
color_enable_r = 4'b1111;
end
`TEX_FORMAT_L8A8: begin
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][7:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(texel_data[i][15:8]);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(0);
formatted_texel_r[i][55:48] = `TEX_COLOR_BITS'(0);
if (i == 0)
color_enable_r = 4'b0011;
end
`TEX_FORMAT_A8: begin
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][7:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(0);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(0);
formatted_texel_r[i][55:48] = `TEX_COLOR_BITS'(0);
if (i == 0)
color_enable_r = 4'b0001;
end
`TEX_FORMAT_L8: begin
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][7:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(0);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(0);
formatted_texel_r[i][55:48] = `TEX_COLOR_BITS'(0);
if (i == 0)
color_enable_r = 4'b0001;
end
default: begin // `TEX_FORMAT_R8G8B8A8:
formatted_texel_r[i][07:00] = `TEX_COLOR_BITS'(texel_data[i][7:0]);
formatted_texel_r[i][23:16] = `TEX_COLOR_BITS'(texel_data[i][15:8]);
formatted_texel_r[i][39:32] = `TEX_COLOR_BITS'(texel_data[i][23:16]);
formatted_texel_r[i][55:48] = `TEX_COLOR_BITS'(texel_data[i][31:24]);
if (i == 0)
color_enable_r = 4'b1111;
end
endcase
end
// pt sampling direct output
case (format) case (format)
`TEX_FORMAT_R5G6B5: begin `TEX_FORMAT_R5G6B5: begin
formatted_pt_r[07:00] = {`TEX_COLOR_BITS{1'b1}}; texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[4:0]);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(texel_data[0][4:0]); texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[10:5]);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(texel_data[0][10:5]); texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[15:11]);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(texel_data[0][15:11]); texel_out_r[31:24] = {`TEX_COLOR_BITS{1'b1}};
end end
`TEX_FORMAT_R4G4B4A4: begin `TEX_FORMAT_R4G4B4A4: begin
formatted_pt_r[07:00] = `TEX_COLOR_BITS'(texel_data[0][3:0]); texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[3:0]);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(texel_data[0][7:4]); texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[7:4]);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(texel_data[0][11:8]); texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[11:8]);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(texel_data[0][15:12]); texel_out_r[31:24] = `TEX_COLOR_BITS'(texel_in[15:12]);
end end
`TEX_FORMAT_L8A8: begin `TEX_FORMAT_L8A8: begin
formatted_pt_r[07:00] = `TEX_COLOR_BITS'(texel_data[0][7:0]); texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(texel_data[0][15:8]); texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(0); texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(0); texel_out_r[31:24] = `TEX_COLOR_BITS'(texel_in[15:8]);
end end
`TEX_FORMAT_A8: begin `TEX_FORMAT_A8: begin
formatted_pt_r[07:00] = `TEX_COLOR_BITS'(texel_data[0][7:0]); texel_out_r[07:00] = `TEX_COLOR_BITS'(0);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(0); texel_out_r[15:08] = `TEX_COLOR_BITS'(0);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(0); texel_out_r[23:16] = `TEX_COLOR_BITS'(0);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(0); texel_out_r[31:24] = `TEX_COLOR_BITS'(texel_in[7:0]);
end end
`TEX_FORMAT_L8: begin `TEX_FORMAT_L8: begin
formatted_pt_r[07:00] = `TEX_COLOR_BITS'(texel_data[0][7:0]); texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(0); texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(0); texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(0); texel_out_r[31:24] = {`TEX_COLOR_BITS{1'b1}};
end end
default: begin // `TEX_FORMAT_R8G8B8A8: default: begin // `TEX_FORMAT_R8G8B8A8:
formatted_pt_r[07:00] = `TEX_COLOR_BITS'(texel_data[0][7:0]); texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[7:0]);
formatted_pt_r[15:08] = `TEX_COLOR_BITS'(texel_data[0][15:8]); texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[15:8]);
formatted_pt_r[23:16] = `TEX_COLOR_BITS'(texel_data[0][23:16]); texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[23:16]);
formatted_pt_r[31:24] = `TEX_COLOR_BITS'(texel_data[0][31:24]); texel_out_r[31:24] = `TEX_COLOR_BITS'(texel_in[31:24]);
end end
endcase endcase
end end
assign color_enable = color_enable_r; assign texel_out = texel_out_r;
assign formatted_pt_texel = formatted_pt_r;
for (genvar i = 0; i < NUM_TEXELS; i++) begin
assign formatted_lerp_texel[i] = formatted_texel_r[i] & 64'h00ff00ff00ff00ff;
end
endmodule endmodule

View File

@@ -2,19 +2,34 @@
module VX_tex_lerp #( module VX_tex_lerp #(
) ( ) (
input wire [`BLEND_FRAC_64-1:0] blend, input wire [`BLEND_FRAC-1:0] blend,
input wire [1:0][63:0] in_texels, input wire [31:0] in1,
input wire [31:0] in2,
output wire [63:0] lerp_texel output wire [31:0] out
); );
wire [63:0] in1_w, in2_w;
wire [63:0] lerp1, lerp2;
`UNUSED_VAR (lerp_i1[55:48]) `UNUSED_VAR (lerp1)
`UNUSED_VAR (lerp2)
wire [63:0] lerp_i1; assign in1_w[15:00] = {8'h00, in1[07:00]};
wire [63:0] lerp_i2; // >> BLEND_FRAC_64 / >> 8 assign in1_w[31:16] = {8'h00, in1[15:08]};
assign in1_w[47:32] = {8'h00, in1[23:16]};
assign in1_w[63:48] = {8'h00, in1[31:24]};
assign lerp_i1 = (in_texels[0] - in_texels[1]) * blend; assign in2_w[15:00] = {8'h00, in2[07:00]};
assign lerp_i2 = in_texels[1] + {8'h00,lerp_i1[63:56], 8'h00,lerp_i1[47:40], 8'h00,lerp_i1[31:24], 8'h00,lerp_i1[15:8]}; assign in2_w[31:16] = {8'h00, in2[15:08]};
assign lerp_texel = lerp_i2 & 64'h00ff00ff00ff00ff; assign in2_w[47:32] = {8'h00, in2[23:16]};
assign in2_w[63:48] = {8'h00, in2[31:24]};
assign lerp1 = (in2_w - in1_w) * blend;
assign lerp2 = in1_w + {8'h00,lerp1[63:56], 8'h00,lerp1[47:40], 8'h00,lerp1[31:24], 8'h00,lerp1[15:8]};
assign out[07:00] = lerp2[07:00];
assign out[15:08] = lerp2[23:16];
assign out[23:16] = lerp2[39:32];
assign out[31:24] = lerp2[55:48];
endmodule endmodule

View File

@@ -39,37 +39,47 @@ module VX_tex_sampler #(
for (genvar i = 0; i < `NUM_THREADS; i++) begin for (genvar i = 0; i < `NUM_THREADS; i++) begin
wire [31:0] req_data_bilerp; wire [3:0][31:0] fmt_texels;
wire [3:0][63:0] formatted_data; wire [31:0] texel_ul, texel_uh, texel_v;
wire [31:0] formatted_pt_data;
wire [`NUM_COLOR_CHANNEL-1:0] color_enable;
VX_tex_format #( wire [`BLEND_FRAC-1:0] blend_u = req_u[i][`BLEND_FRAC-1:0];
.CORE_ID (CORE_ID), wire [`BLEND_FRAC-1:0] blend_v = req_v[i][`BLEND_FRAC-1:0];
.NUM_TEXELS (4)
) tex_format (
.texel_data (req_texels[i]),
.format (req_format),
.color_enable (color_enable), for (genvar j = 0; j < 4; j++) begin
.formatted_lerp_texel(formatted_data), VX_tex_format #(
.formatted_pt_texel(formatted_pt_data) .CORE_ID (CORE_ID)
) tex_format (
.format (req_format),
.texel_in (req_texels[i][j]),
.texel_out (fmt_texels[j])
);
end
VX_tex_lerp #(
) tex_lerp_ul (
.blend (blend_u),
.in1 (fmt_texels[0]),
.in2 (fmt_texels[1]),
.out (texel_ul)
); );
VX_tex_bilerp #( VX_tex_lerp #(
.CORE_ID (CORE_ID) ) tex_lerp_uh (
) tex_bilerp ( .blend (blend_u),
.blendU (req_u[i][`BLEND_FRAC_64-1:0]), .in1 (fmt_texels[2]),
.blendV (req_v[i][`BLEND_FRAC_64-1:0]), .in2 (fmt_texels[3]),
.out (texel_uh)
.color_enable (color_enable),
.texels (formatted_data),
.sampled_data (req_data_bilerp)
); );
assign req_data[i] = (req_filter == `TEX_FILTER_BITS'(0)) ? formatted_pt_data : req_data_bilerp; VX_tex_lerp #(
) tex_lerp_v (
.blend (blend_v),
.in1 (texel_ul),
.in2 (texel_uh),
.out (texel_v)
);
assign req_data[i] = req_filter ? texel_v : fmt_texels[0];
end end
assign stall_out = rsp_valid && ~rsp_ready; assign stall_out = rsp_valid && ~rsp_ready;

View File

@@ -190,7 +190,7 @@ module VX_tex_unit #(
wire [`NR_BITS-1:0] rsp_rd; wire [`NR_BITS-1:0] rsp_rd;
wire rsp_wb; wire rsp_wb;
assign {rsp_format, rsp_u, rsp_v, rsp_rd, rsp_wb} = mem_rsp_info; assign {rsp_u, rsp_v, rsp_format, rsp_rd, rsp_wb} = mem_rsp_info;
VX_tex_sampler #( VX_tex_sampler #(
.CORE_ID (CORE_ID) .CORE_ID (CORE_ID)