From 2702c90d7a39fca2a3319c5e915fd290cb31fc70 Mon Sep 17 00:00:00 2001 From: Radosław Kujawa Date: Fri, 17 Jul 2026 14:54:32 +0200 Subject: Initial import. --- src/mesa/drivers/verite/rlgl.h | 194 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 src/mesa/drivers/verite/rlgl.h (limited to 'src/mesa/drivers/verite/rlgl.h') diff --git a/src/mesa/drivers/verite/rlgl.h b/src/mesa/drivers/verite/rlgl.h new file mode 100644 index 0000000..002134c --- /dev/null +++ b/src/mesa/drivers/verite/rlgl.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2026 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Radoslaw Kujawa. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RLGL_H +#define RLGL_H + +#include +#include "libv3d.h" + +/* texel formats (PE SrcFmt/DstFmt encodings) */ +#define RLGL_FMT_565 4 +#define RLGL_FMT_4444 5 +#define RLGL_FMT_1555 6 + +/* + * blend factors + */ +#define RLGL_BL_ZERO 6 /* Blend0 */ +#define RLGL_BL_ONE 7 /* Blend1 */ +#define RLGL_BL_SRCALPHA 2 +#define RLGL_BL_INVSRCALPHA 3 +#define RLGL_BL_OTHERCOLOR 0 /* dst side: src color; src: dst */ +#define RLGL_BL_INVOTHERCOLOR 1 +#define RLGL_BL_OWNCOLOR 10 /* own color - no GL equivalent */ +#define RLGL_BL_INVOWNCOLOR 11 +/* legacy names (dst-side view), kept for minigl */ +#define RLGL_BL_SRCCOLOR RLGL_BL_OTHERCOLOR +#define RLGL_BL_INVSRCCOLOR RLGL_BL_INVOTHERCOLOR + +struct rlgl_tex { + uint32_t addr; /* VRAM; 0 = not resident */ + uint16_t w, h; /* texels, powers of two */ + uint32_t srcstride; /* encoded (Src1<<4)|Src0 */ + uint32_t fmt; /* RLGL_FMT_* */ +}; + +struct rlgl { + struct v3d v; + uint32_t fb[2], zbuf; + uint32_t scratch; /* glCopyPixels seed scratch surface */ + int back; + struct rlgl_tex pt_tex; /* AA-point radial coverage tex (lazy; + * addr 0 = not yet created) */ + /* redundant-state cache */ + uint32_t cur_tex; + int cur_func; /* PE SrcFunc currently set */ + int env_mod; /* SrcFunc code for textured draws */ + int fog_on; /* emit the KFXYZUVQ fog channel */ + int frames; + /* perf: swap-to-swap frame timing (RLGL_STATS) + counters */ + uint64_t tris; + uint64_t frame_ns_tot, frame_ns_min, frame_ns_max; + uint64_t last_swap_ns; + int stats_printed; +}; + +/* per-vertex layout handed to rlgl_tri: the KXYZUVQ order */ +struct rlgl_vtx { + float r, g, b; /* 0..255 */ + float x, y; /* screen pixels */ + float z; /* 0..65535, smaller = nearer */ + float u, v; /* texels */ + float q; /* 1/w (any consistent scale) */ + float f; /* fog factor 0..255, 255 = no fog (fog_on only) */ +}; + +/* diagnostic: 1 = disable redundant-state caches (VRMESA_NOCACHE probe) */ +extern int rlgl_force_rebind; + +int rlgl_init(struct rlgl *, const char *ucpath); +void rlgl_shutdown(struct rlgl *); + +int rlgl_tex_init(struct rlgl_tex *, int w, int h, uint32_t fmt); +int rlgl_tex_alloc(struct rlgl *, struct rlgl_tex *); +int rlgl_tex_pyramid(struct rlgl *, struct rlgl_tex *levs, int nlev); +int rlgl_tex_create(struct rlgl *, struct rlgl_tex *, int w, int h, + uint32_t fmt); +void rlgl_tex_free(struct rlgl *, struct rlgl_tex *); +int rlgl_tex_upload(struct rlgl *, struct rlgl_tex *, + const uint16_t *texels); +int rlgl_tex_upload_rows(struct rlgl *, struct rlgl_tex *, + const uint16_t *texels, int y, int rows); +void rlgl_tex_bind(struct rlgl *, const struct rlgl_tex *); +void rlgl_tex_env(struct rlgl *, int modulate); +/* PE SrcFunc codes (spec table: 1=replace 2=decal 3=modulate) */ +#define RLGL_ENV_REPLACE 1 +#define RLGL_ENV_DECAL 2 +#define RLGL_ENV_MODULATE 3 +void rlgl_tex_env_code(struct rlgl *, int srcfunc_code); +/* + * Per-axis clamp-to-edge (UClamp b15 / VClamp b16 of SrcMode). + */ +void rlgl_tex_wrap(struct rlgl *, int uclamp, int vclamp); +void rlgl_tex_filter(struct rlgl *, int bilinear); + +/* PE ZBufMode compare codes (silicon-proven: LT ztest, LE GLQuake) */ +#define RLGL_Z_LT 1 +#define RLGL_Z_LE 3 + +void rlgl_depth_test(struct rlgl *, int enable_lt_or_le); +void rlgl_depth_func(struct rlgl *, int enable, int pe_code); +void rlgl_depth_mask(struct rlgl *, int write); +void rlgl_blend(struct rlgl *, int enable, uint32_t srcf, uint32_t dstf); +void rlgl_alpha_test(struct rlgl *, int enable, uint32_t thresh8); +/* GL window-coord box (bottom-left origin); flips to the PE top-left */ +void rlgl_scissor(struct rlgl *, int x, int y, int w, int h); +/* 565 plane write mask; args are glColorMask R/G/B booleans (alpha n/a) */ +void rlgl_color_mask(struct rlgl *, int r, int g, int b); +/* PE raster op (ALUMode 4-bit ROP code); disabled restores COPY */ +void rlgl_logic_op(struct rlgl *, int enable, int code); +/* PE 4x4 ordered dither on 565 writes (GL_DITHER) */ +void rlgl_dither(struct rlgl *, int enable); +/* + * Per-vertex fog (GL_FOG) + */ +void rlgl_fog(struct rlgl *, int enable, uint32_t rgb888); + +void rlgl_clear(struct rlgl *, int color, uint32_t rgb565, + int depth); +/* + * glDrawPixels fast path + */ +int rlgl_draw_row(struct rlgl *, int x, int wy, int w, + const uint16_t *row565); +/* + * Hardware glCopyPixels (GL_COLOR) + */ +int rlgl_copy_rect(struct rlgl *, uint32_t src_base, int src_w, + uint32_t dst_base, int dst_w, int sx, int sy, int dx, int dy, + int w, int h); +/* + * Hardware glCopyTexSubImage + */ +int rlgl_copy_to_tex(struct rlgl *, uint32_t fb_base, int fb_h, + uint32_t tex_base, int tex_aw, int sx, int sy_gl, int dx, int dy, + int w, int h); +void rlgl_tri(struct rlgl *, const struct rlgl_vtx *, + const struct rlgl_vtx *, const struct rlgl_vtx *); +/* + * Native hardware lines from a 2-vertex KXYZ stream (only r,g,b,x,y,z + * used). + */ +void rlgl_line(struct rlgl *, const struct rlgl_vtx *, + const struct rlgl_vtx *); +void rlgl_aaline(struct rlgl *, const struct rlgl_vtx *, + const struct rlgl_vtx *); +/* + * Native anti-aliased points (GL_POINT_SMOOTH) + */ +void rlgl_aapoint_begin(struct rlgl *); +void rlgl_aapoint(struct rlgl *, const struct rlgl_vtx *, float size); +void rlgl_aapoint_end(struct rlgl *); +/* + * Native hardware primitive strips/fans + */ +void rlgl_tristrip(struct rlgl *, const struct rlgl_vtx *v, int n); +void rlgl_trifan(struct rlgl *, const struct rlgl_vtx *v, int n); +/* + * Bulk indexed emit: verts9 = packed 9-float wire records + * (r,g,b,x,y,z,u,v,q), idx = 3*ntris vertex indices into verts9. + */ +void rlgl_tris_idx(struct rlgl *, const float *verts9, + const uint8_t *idx, int ntris); +int rlgl_swap(struct rlgl *); +int rlgl_finish(struct rlgl *); +void rlgl_stats_print(struct rlgl *); + +#endif /* RLGL_H */ -- cgit