Snapshot: fog implementation + fidelity tooling baseline (pre bilinear-clamp fix)

Per-vertex GS fog end-to-end (gs_stub emit incl. persp_emit5, gs_prim_list_feeder
XYZ2->XYZF2 on PRIM.FGE, gs_make_sh3_scheduler_fixture.py F/FGE packing), new fog
TBs, fidelity attribution tooling. Functional baseline before removing the dead
bilinear lerp8 clamps (Codex: 161-node comb loop -> -0.042ns setup fail).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-20 19:56:46 -04:00
parent ec82764bef
commit ba74bbd5aa
476 changed files with 696247 additions and 130119 deletions
+98 -17
View File
@@ -30,7 +30,10 @@
`timescale 1ns/1ps
module tb_gs_raster_pipeline;
module tb_gs_raster_pipeline #(
parameter bit USE_SUBPIXEL = 1'b0,
parameter int GRAD_CYCLES = 1
);
logic clk;
logic rst_n;
@@ -64,6 +67,7 @@ module tb_gs_raster_pipeline;
logic [11:0] raster_pixel_x_q, raster_pixel_y_q;
logic [63:0] raster_pixel_color_q;
logic [31:0] raster_pixel_fb_addr_q;
logic [31:0] raster_pixel_z_q;
logic raster_active;
logic raster_overflow;
logic raster_degenerate;
@@ -73,7 +77,11 @@ module tb_gs_raster_pipeline;
logic [63:0] ev_arg0, ev_arg1, ev_arg2, ev_arg3;
logic [31:0] ev_flags;
gs_stub u_gs (
gs_stub #(
.SUBPIXEL_XY(USE_SUBPIXEL),
.GRAD_SEQ_DIVIDER(1'b0),
.GRAD_DIV_CYCLES(GRAD_CYCLES)
) u_gs (
.clk(clk), .rst_n(rst_n),
.reg_wr_en(1'b0), .reg_wr_addr(16'd0), .reg_wr_data(64'd0),
.gif_reg_wr_en(gif_reg_wr_en),
@@ -110,6 +118,7 @@ module tb_gs_raster_pipeline;
.raster_pixel_y_q(raster_pixel_y_q),
.raster_pixel_color_q(raster_pixel_color_q),
.raster_pixel_fb_addr_q(raster_pixel_fb_addr_q),
.raster_pixel_z_q(raster_pixel_z_q),
.raster_active(raster_active),
.raster_overflow(raster_overflow),
.raster_degenerate(raster_degenerate),
@@ -130,17 +139,32 @@ module tb_gs_raster_pipeline;
int emit_cycles [0:31];
int emit_count;
int errors;
logic [7:0] sub_r [0:3][0:3];
logic [31:0] sub_z [0:3][0:3];
logic sub_seen [0:3][0:3];
initial begin
v_close_cycle = -1;
emit_count = 0;
errors = 0;
for (int y = 0; y < 4; y++) begin
for (int x = 0; x < 4; x++) begin
sub_r[y][x] = 8'd0;
sub_z[y][x] = 32'd0;
sub_seen[y][x] = 1'b0;
end
end
end
always_ff @(posedge clk) begin
if (rst_n && raster_pixel_emit && emit_count < 32) begin
emit_cycles[emit_count] <= cycle_idx;
emit_count <= emit_count + 1;
if (USE_SUBPIXEL && raster_pixel_x_q < 4 && raster_pixel_y_q < 4) begin
sub_r[raster_pixel_y_q][raster_pixel_x_q] <= raster_pixel_color_q[7:0];
sub_z[raster_pixel_y_q][raster_pixel_x_q] <= raster_pixel_z_q;
sub_seen[raster_pixel_y_q][raster_pixel_x_q] <= 1'b1;
end
end
end
@@ -167,6 +191,21 @@ module tb_gs_raster_pipeline;
return {32'd0, y_int, 4'd0, x_int, 4'd0};
endfunction
function automatic logic [63:0] xyz2_sub(input logic [15:0] x_12_4,
input logic [15:0] y_12_4);
return {32'd0, y_12_4, x_12_4};
endfunction
function automatic logic [63:0] xyz2_sub_z(input logic [15:0] x_12_4,
input logic [15:0] y_12_4,
input logic [31:0] z);
return {z, y_12_4, x_12_4};
endfunction
function automatic logic [63:0] rgbaq_r(input logic [7:0] r);
return {32'd0, 8'hff, 8'd0, 8'd0, r};
endfunction
localparam logic [7:0] R_PRIM = 8'h00;
localparam logic [7:0] R_RGBAQ = 8'h01;
localparam logic [7:0] R_XYZ2 = 8'h05;
@@ -186,13 +225,27 @@ module tb_gs_raster_pipeline;
rst_n = 1'b1;
repeat (2) @(posedge clk);
drive_reg(R_PRIM, PRIM_SPRITE);
drive_reg(R_PRIM, USE_SUBPIXEL ? 64'd3 : PRIM_SPRITE);
drive_reg(R_FRAME_1, FRAME_1_VAL);
drive_reg(R_RGBAQ, RGBAQ_VAL);
// 4×4 sprite — bbox=[0..3]×[0..3] = 16 pixels.
drive_reg(R_XYZ2, xyz2_data(12'd0, 12'd0)); // v1
drive_reg(R_XYZ2, xyz2_data(12'd3, 12'd3)); // v2 — close S1
if (USE_SUBPIXEL) begin
// Right triangle at (0.75,0.75),(3.75,0.75),(0.75,3.75).
// Pixel-center 12.4 coverage is exactly (1,1),(2,1),(1,2).
// R and Z form exact planes: dR/dx=32, dR/dy=64,
// dZ/dx=100, dZ/dy=200. This checks fractional gradient
// setup and +0.5 pixel-center evaluation as well as coverage.
drive_reg(R_RGBAQ, rgbaq_r(8'd0));
drive_reg(R_XYZ2, xyz2_sub_z(16'h000c,16'h000c,32'd1000));
drive_reg(R_RGBAQ, rgbaq_r(8'd96));
drive_reg(R_XYZ2, xyz2_sub_z(16'h003c,16'h000c,32'd1300));
drive_reg(R_RGBAQ, rgbaq_r(8'd192));
drive_reg(R_XYZ2, xyz2_sub_z(16'h000c,16'h003c,32'd1600));
end else begin
// 4×4 sprite — bbox=[0..3]×[0..3] = 16 pixels.
drive_reg(R_XYZ2, xyz2_data(12'd0, 12'd0));
drive_reg(R_XYZ2, xyz2_data(12'd3, 12'd3));
end
v_close_cycle = cycle_idx; // capture posedge index of v2 close
// Stop driving (deassert gif_reg_wr_en) and let the
@@ -200,7 +253,12 @@ module tb_gs_raster_pipeline;
// high and re-commits the v2 vertex every cycle, kicking
// off extra sprites and overflowing the FIFO.
drive_idle();
repeat (40) @(posedge clk);
// A TRI cannot pop until all 14 affine gradients are ready. The
// production combinational-divider FSM spends GRAD_CYCLES settle
// cycles plus select/commit overhead per step, so scale this gate
// with the configured latency instead of falsely timing out at the
// legacy fixed 40 cycles.
repeat (USE_SUBPIXEL ? (14 * (GRAD_CYCLES + 2) + 20) : 40) @(posedge clk);
// ---- Assertions ----
$display("[tb_gs_raster_pipeline] v_close_cycle=%0d emit_count=%0d raster_pixel_emit_count=%0d raster_overflow=%b",
@@ -209,12 +267,13 @@ module tb_gs_raster_pipeline;
$display("[tb_gs_raster_pipeline] emit[%0d] @ cyc=%0d", i, emit_cycles[i]);
end
if (emit_count != 16) begin
$error("emit_count=%0d (expected 16 for 4×4 sprite)", emit_count);
if (emit_count != (USE_SUBPIXEL ? 3 : 16)) begin
$error("emit_count=%0d (expected %0d)", emit_count, USE_SUBPIXEL ? 3 : 16);
errors = errors + 1;
end
if (raster_pixel_emit_count != 32'd16) begin
$error("raster_pixel_emit_count=%0d (expected 16)", raster_pixel_emit_count);
if (raster_pixel_emit_count != (USE_SUBPIXEL ? 32'd3 : 32'd16)) begin
$error("raster_pixel_emit_count=%0d (expected %0d)", raster_pixel_emit_count,
USE_SUBPIXEL ? 3 : 16);
errors = errors + 1;
end
if (raster_overflow !== 1'b0) begin
@@ -222,9 +281,27 @@ module tb_gs_raster_pipeline;
errors = errors + 1;
end
if (USE_SUBPIXEL) begin
if (!sub_seen[1][1] || sub_r[1][1] != 8'd72 || sub_z[1][1] != 32'd1225) begin
$error("subpixel attr (1,1): seen=%b R=%0d Z=%0d expected R=72 Z=1225",
sub_seen[1][1], sub_r[1][1], sub_z[1][1]);
errors = errors + 1;
end
if (!sub_seen[1][2] || sub_r[1][2] != 8'd104 || sub_z[1][2] != 32'd1325) begin
$error("subpixel attr (2,1): seen=%b R=%0d Z=%0d expected R=104 Z=1325",
sub_seen[1][2], sub_r[1][2], sub_z[1][2]);
errors = errors + 1;
end
if (!sub_seen[2][1] || sub_r[2][1] != 8'd136 || sub_z[2][1] != 32'd1425) begin
$error("subpixel attr (1,2): seen=%b R=%0d Z=%0d expected R=136 Z=1425",
sub_seen[2][1], sub_r[2][1], sub_z[2][1]);
errors = errors + 1;
end
end
// Throughput: every consecutive pair of emits must be on
// adjacent cycles (delta == 1). 1 pixel/cycle.
for (int i = 1; i < emit_count; i++) begin
for (int i = 1; i < emit_count && !USE_SUBPIXEL; i++) begin
int d;
d = emit_cycles[i] - emit_cycles[i-1];
if (d != 1) begin
@@ -234,15 +311,19 @@ module tb_gs_raster_pipeline;
end
end
// Latency: 5 posedges from v_close to first observed
// raster_pixel_emit (see header for breakdown).
if (emit_count > 0) begin
// Latency: 6 posedges from v_close to first observed raster_pixel_emit. Ch357 (Codex) pipelined the attr_ram
// WRITE (register the assembled word on push, commit to M20K the next cycle + attr_pending holds the slot until
// the write lands), so the assembled prim is poppable at push+2 instead of push+1 — +1 cycle vs the old
// v_close+5. Correctness is unchanged (emit_count/overflow identical); this pins the new pipeline depth.
// The TRI subpixel case waits for the shared gradient engine before
// pop; this latency assertion is specifically the legacy SPRITE pipe.
if (emit_count > 0 && !USE_SUBPIXEL) begin
int expected_first;
int actual_first;
expected_first = v_close_cycle + 5;
expected_first = v_close_cycle + 6;
actual_first = emit_cycles[0];
if (actual_first != expected_first) begin
$error("first-emit latency: emit[0]@cyc=%0d (expected %0d = v_close+5)",
$error("first-emit latency: emit[0]@cyc=%0d (expected %0d = v_close+6, Ch357 attr-write pipeline)",
actual_first, expected_first);
errors = errors + 1;
end