shithub: libgraphics

Download patch

ref: cf3e0cb65c03955ef18624a50b9e33c3f6e8c6e5
parent: c40a1238f24534b5f433308d92308e1481464141
author: rodri <rgl@antares-labs.eu>
date: Wed Apr 24 08:38:42 EDT 2024

render: add rasterizer init params and per-proc identification.

--- a/camera.c
+++ b/camera.c
@@ -108,9 +108,9 @@
 	t1 = nanosec();
 	c->vp->fbctl->swap(c->vp->fbctl);
 
+	updatestats(c, t1-t0);
 	updatetimes(c, job);
+
 	chanfree(job->donec);
 	free(job);
-
-	updatestats(c, t1-t0);
 }
--- a/internal.h
+++ b/internal.h
@@ -1,19 +1,27 @@
 typedef struct Tilerparam Tilerparam;
+typedef struct Rasterparam Rasterparam;
 typedef struct Rastertask Rastertask;
 
-struct Rastertask
-{
-	SUparams *params;
-	Rectangle wr;		/* working rect */
-	Primitive p;
-};
-
 struct Tilerparam
 {
+	int id;
 	Channel *paramsc;
-	Channel **tasksc;	/* Channel*[nproc] */
+	Channel **taskchans;	/* Channel*[nproc] */
 	Rectangle *wr;		/* Rectangle[nproc] */
 	ulong nproc;
+};
+
+struct Rasterparam
+{
+	int id;
+	Channel *taskc;
+};
+
+struct Rastertask
+{
+	SUparams *params;
+	Rectangle wr;		/* working rect */
+	Primitive p;
 };
 
 /* alloc */
--- a/render.c
+++ b/render.c
@@ -358,18 +358,18 @@
 static void
 rasterizer(void *arg)
 {
-	Channel *taskc;
+	Rasterparam *rp;
 	Rastertask *task;
 	SUparams *params;
 	Memimage *frag;
 	uvlong t0;
 
-	threadsetname("rasterizer");
-
-	taskc = arg;
+	rp = arg;
 	frag = rgb(DBlack);
 
-	while((task = recvp(taskc)) != nil){
+	threadsetname("rasterizer %d", rp->id);
+
+	while((task = recvp(rp->taskc)) != nil){
 		t0 = nanosec();
 
 		params = task->params;
@@ -411,19 +411,19 @@
 	Point3 n;				/* surface normal */
 	Primitive *p;				/* primitives to raster */
 	Rectangle *wr, bbox;
-	Channel **taskc;
+	Channel **taskchans;
 	ulong Δy, nproc;
 	int i, np;
 	uvlong t0;
 
-	threadsetname("tilerdurden");
-
 	tp = arg;
 	p = emalloc(sizeof(*p)*16);
-	taskc = tp->tasksc;
+	taskchans = tp->taskchans;
 	nproc = tp->nproc;
 	wr = emalloc(nproc*sizeof(Rectangle));
 
+	threadsetname("tilerdurden %d", tp->id);
+
 	while((params = recvp(tp->paramsc)) != nil){
 		t0 = nanosec();
 		if(params->job->times.Tn.t0 == 0)
@@ -437,7 +437,7 @@
 					task = emalloc(sizeof *task);
 					memset(task, 0, sizeof *task);
 					task->params = params;
-					sendp(taskc[i], task);
+					sendp(taskchans[i], task);
 				}
 			}
 			continue;
@@ -555,7 +555,7 @@
 						task->p.v[0] = dupvertex(&p[np].v[0]);
 						task->p.v[1] = dupvertex(&p[np].v[1]);
 						task->p.v[2] = dupvertex(&p[np].v[2]);
-						sendp(taskc[i], task);
+						sendp(taskchans[i], task);
 					}
 //skiptri:
 				delvattrs(&p[np].v[0]);
@@ -571,8 +571,9 @@
 static void
 entityproc(void *arg)
 {
-	Channel *paramsin, **paramsout, **taskc;
+	Channel *paramsin, **paramsout, **taskchans;
 	Tilerparam *tp;
+	Rasterparam *rp;
 	SUparams *params, *newparams;
 	OBJElem **eb, **ee;
 	char *nprocs;
@@ -591,18 +592,21 @@
 	free(nprocs);
 
 	paramsout = emalloc(nproc*sizeof(*paramsout));
-	taskc = emalloc(nproc*sizeof(*taskc));
+	taskchans = emalloc(nproc*sizeof(*taskchans));
 	for(i = 0; i < nproc; i++){
 		paramsout[i] = chancreate(sizeof(SUparams*), 8);
 		tp = emalloc(sizeof *tp);
+		tp->id = i;
 		tp->paramsc = paramsout[i];
-		tp->tasksc = taskc;
+		tp->taskchans = taskchans;
 		tp->nproc = nproc;
 		proccreate(tilerdurden, tp, mainstacksize);
 	}
 	for(i = 0; i < nproc; i++){
-		taskc[i] = chancreate(sizeof(Rastertask*), 32);
-		proccreate(rasterizer, taskc[i], mainstacksize);
+		rp = emalloc(sizeof *rp);
+		rp->id = i;
+		rp->taskc = taskchans[i] = chancreate(sizeof(Rastertask*), 32);
+		proccreate(rasterizer, rp, mainstacksize);
 	}
 
 	while((params = recvp(paramsin)) != nil){