From bf6b4e2e8ebb63f6b8466bc98650ce75f3bdc79f Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sun, 12 Nov 2023 01:37:02 -0600 Subject: rtl/gfx: implement fragment shading --- rtl/gfx/gfx_frag_shade.sv | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 rtl/gfx/gfx_frag_shade.sv (limited to 'rtl/gfx/gfx_frag_shade.sv') diff --git a/rtl/gfx/gfx_frag_shade.sv b/rtl/gfx/gfx_frag_shade.sv new file mode 100644 index 0000000..d2ad7ce --- /dev/null +++ b/rtl/gfx/gfx_frag_shade.sv @@ -0,0 +1,53 @@ +`include "gfx/gfx_defs.sv" + +module gfx_frag_shade +( + input logic clk, + + input fixed b1, + b2, + input color_lerp_lanes argb0, + argb1_argb0, + argb2_argb0, + input logic stall, + + output rgb32 color +); + + struct packed + { + logic sign; + logic[$bits(fixed) - `FIXED_FRAC - 2:0] out_of_range; + color8 color; + logic[`FIXED_FRAC - $bits(color8) - 1:0] sub; + } lerped[`COLOR_CHANNELS]; + + fixed channel_lerp[`COLOR_CHANNELS]; + color8[`COLOR_CHANNELS - 1:0] out; + + assign color = out; + + genvar i; + generate + for (i = 0; i < `COLOR_CHANNELS; ++i) begin: channels + assign lerped[i] = channel_lerp[i]; + + gfx_lerp lerp + ( + .q(channel_lerp[i]), + .q0(argb0[i]), + .q1_q0(argb1_argb0[i]), + .q2_q0(argb2_argb0[i]), + .* + ); + + always_ff @(posedge clk) + if (!stall) begin + out[i] <= lerped[i].color; + if (lerped[i].sign || |lerped[i].out_of_range) + out[i] <= {($bits(color8)){!lerped[i].sign}}; + end + end + endgenerate + +endmodule -- cgit v1.2.3