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/libv3d.h | 138 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/mesa/drivers/verite/libv3d.h (limited to 'src/mesa/drivers/verite/libv3d.h') diff --git a/src/mesa/drivers/verite/libv3d.h b/src/mesa/drivers/verite/libv3d.h new file mode 100644 index 0000000..4ee44b1 --- /dev/null +++ b/src/mesa/drivers/verite/libv3d.h @@ -0,0 +1,138 @@ +/* + * 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. + */ + +/* + * libv3d - thin userland layer over /dev/verite3d (verite3dio.h), + * shaped after the RRedline command-buffer model. Uses the v2000gl.uc + * command numbers (sync=8, context_init=2, exit=0) and the decoded + * state-class words. + */ +#ifndef LIBV3D_H +#define LIBV3D_H + +#include +#include "verite3dio.h" + +/* + * Perf counters + */ +struct v3d_stats { + uint64_t words; /* words emitted into slots */ + uint64_t submits, submit_bytes, submit_ns; + uint64_t syncs, sync_ns; + uint64_t flips, flip_ns; + uint64_t uploads, upload_bytes; + uint64_t st_calls, texbinds; +}; + +struct v3d { + int fd; + uint32_t *slot[V3D_RING_SLOTS]; + uint8_t *vram; /* lazy full-VRAM read mapping */ + int cur; /* slot being filled */ + uint32_t n; /* words used in cur */ + /* geometry from the kernel */ + uint32_t ctx_base, memsize, pool_base; + uint32_t width, height, stride, pe_stride; + /* RLGL_STATS / RLGL_NULLDRAW / RLGL_NOSYNC / RLGL_NOFLIP / + * RLGL_TEARFLIP */ + int opt_stats, opt_nulldraw, opt_nosync, opt_noflip; + int opt_tearflip; + struct v3d_stats st; +}; + +/* GL blob FIFO ABI */ +#define V3D_GL_EXIT 0 +#define V3D_GL_CTX_INIT 2 +#define V3D_GL_SYNC 8 +#define V3D_GL_MEM_WRITE 9 +#define V3D_GL_CLEAR_RECT 13 +#define V3D_GL_LINE 16 /* hw Bresenham line (rdraw2) */ +#define V3D_GL_AALINE 20 /* coverage-graded AA line */ +#define V3D_GL_TRIANGLE 24 +#define V3D_GL_TRISTRIP 26 /* hw tri-strip start (cont word 48) */ +#define V3D_GL_TRIFAN 27 /* hw tri-fan start (cont word 49) */ +#define V3D_GL_AAPOINT 50 /* coverage-graded AA point */ +#define V3D_GL_STRIP_CONT 48 /* tristrip_third_vertex continuation */ +#define V3D_GL_FAN_CONT 49 /* trifan continuation (single vtx) */ + +/* PE register indices (state class 1 writes, value pre-shifted) */ +#define V3D_PE_SRCBASE 0 +#define V3D_PE_STRIDE 3 +#define V3D_PE_DSTBASE 4 +#define V3D_PE_DSTFMT 6 +#define V3D_PE_PMASK 7 +#define V3D_PE_SCISSORX 14 +#define V3D_PE_SCISSORY 15 +#define V3D_PE_ZBASE 16 +#define V3D_PE_FGCOLOR 19 +#define V3D_PE_FOGCOLOR 21 /* 0x00RRGGBB */ +#define V3D_PE_SRCFMT 48 +#define V3D_PE_SRCFUNC 49 /* value << 4 */ +#define V3D_PE_SRCFILTER 50 /* value << 7 */ +#define V3D_PE_ALUMODE 64 /* bits 3:0 */ +#define V3D_PE_BLENDSRCFUNC 65 /* value << 4 */ +#define V3D_PE_BLENDDSTFUNC 66 /* value << 8 */ +#define V3D_PE_ZBUFMODE 67 /* value << 12 */ +#define V3D_PE_ZBUFWRMODE 68 /* value << 16 */ +#define V3D_PE_BLENDENABLE 70 /* value << 19 */ +#define V3D_PE_DITHEREN 71 /* value << 20 */ +#define V3D_PE_FOGEN 72 /* value << 21 */ +#define V3D_PE_DSTRDDIS 74 /* value << 23 */ + +uint64_t v3d_now_ns(void); +int v3d_open(struct v3d *, const char *devpath, const char *ucpath); +void v3d_close(struct v3d *); +/* + * VRAM window + */ +const uint8_t *v3d_vram(struct v3d *); +void v3d_emit(struct v3d *, const uint32_t *, uint32_t); +void v3d_emit1(struct v3d *, uint32_t); +void v3d_emitf(struct v3d *, float); + +uint32_t *v3d_reserve(struct v3d *, uint32_t nwords); +void v3d_commit(struct v3d *, uint32_t nwords); +int v3d_flush(struct v3d *); +int v3d_sync(struct v3d *); +int v3d_alloc(struct v3d *, uint32_t, uint32_t, uint32_t *); +int v3d_mode(struct v3d *, uint32_t depth, uint32_t frame_base); +int v3d_flip(struct v3d *, uint32_t frame_base); + +/* state class 1: single PE register write (pre-shifted value) */ +void v3d_st(struct v3d *, uint32_t reg, uint32_t val); +/* state class 4: full texture bind */ +void v3d_texbind(struct v3d *, uint32_t addr, uint32_t srcstride, + uint32_t w, uint32_t h, uint32_t uscale, uint32_t vscale); +/* mem_write upload (chunks as needed) and engine-side clear */ +int v3d_upload(struct v3d *, uint32_t dst, const void *, uint32_t); +void v3d_clear(struct v3d *, uint32_t addr, uint32_t stride, + uint32_t wbytes, uint32_t h, uint32_t val); + +#endif /* LIBV3D_H */ -- cgit