shithub: gpufs

Download patch

ref: 8a6851fa526de6f5dcf5ddabb5609f3a85929e6f
parent: 77e627174769161f3284c854073f21ea9181d982
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Feb 17 10:18:10 EST 2024

full pool management commands

--- a/README
+++ b/README
@@ -3,6 +3,28 @@
 EVERYTHING CURRENTLY IS A BIG TODO!
 
 
+FILESYSTEM COMMANDS
+
+/ctl
+
+n(ew) s(hader) - create new shader
+n(ew) b(uffer) <len> - create new buffer with length len
+n(ew) p(ool) <numsets> - create new descriptor pool with numsets number of descriptor sets
+b(ind) <buffer> <pool> <set> <binding> - bind buffer to pool/set/binding
+s(et) <pool> <set> <numbindings> - allocate pool/set with numbindings number of bindings
+
+
+/ShaderId/ctl
+
+c(ompile) - compile shader
+r(un) - run shader
+b(ind) <pool> - bind shader to pool
+
+
+/BufferId/ctl
+
+
+----------------
 
 GPU filesystem (gpufs; TODO)
 
--- a/gpufs.c
+++ b/gpufs.c
@@ -34,6 +34,7 @@
 enum {
 	Qroot,
 		Qrctl,
+		Qdesc,
 		Qobject,
 			Qctl,
 			Qbuffer,
@@ -43,6 +44,7 @@
 static char *nametab[] = {
 	"/",
 		"ctl",
+		"desc",
 		nil,
 			"ctl",
 			"buffer",
@@ -67,6 +69,18 @@
 
 String *fsqueue = nil;
 
+static void
+fsqprint(char *fmt, ...)
+{
+	char sbuf[512];
+	
+	va_list arg;
+	va_start(arg, fmt);
+	vseprint(sbuf, sbuf + sizeof(sbuf), fmt, arg);
+	va_end(arg);
+	fsqueue = s_append(fsqueue, sbuf);
+}
+
 int debug = 0;
 
 static char *user;
@@ -120,6 +134,9 @@
 	case Qrctl:
 	case Qctl:
 		break;
+	case Qdesc:
+		d->length = getnumdescpools();
+		break;
 	case Qbuffer:
 		d->length = getbufferlength(OBJECTID(aux));
 		break;
@@ -200,6 +217,12 @@
 		readrctl(r);
 		respond(r, nil);
 		return;
+	case Qdesc:
+		s = getpoolinfo();
+		if (s)
+			readstr(r, s);
+		respond(r, nil);
+		return;
 	case Qshader:
 		r->ofcall.count = readshader(OBJECTID(f), r->ofcall.data, r->ifcall.count, r->ifcall.offset);
 		respond(r, nil);
@@ -313,33 +336,27 @@
 	respond(r, nil);
 }
 
-static int
+static vlong
 newshader(void)
 {
-	int id = genshader();
+	vlong id = genshader();
 	if (id < 0) {
 		return -1;
 	}
 	
-	char *s = smprint("s %d\n", id);
-	s_append(fsqueue, s);
-	free(s);
-	
+	fsqprint("s %lld\n", id);
 	return id;
 }
 
-static int
+static vlong
 newbuffer(long len)
 {
-	int id = genbuffer(len);
+	vlong id = genbuffer(len);
 	if (id < 0) {
 		return -1;
 	}
 	
-	char *s = smprint("b %d\n", id);
-	s_append(fsqueue, s);
-	free(s);
-	
+	fsqprint("b %lld\n", id);
 	return id;
 }
 
@@ -348,7 +365,9 @@
 {
 	// n(ew) s(hader)
 	// n(ew) b(uffer) <len>
+	// n(ew) p(ool) <numsets>
 	// b(ind) <buffer> <pool> <set> <binding>
+	// s(et) <pool> <set> <numbindings>
 	
 	if (argc <= 0)
 		return;
@@ -373,6 +392,17 @@
 					respond(r, nil);
 				return;
 			}
+			if (strcmp(argv[1], "p") == 0) {
+				int len = atol(argv[2]);
+				int pool = gendescpool(len);
+				if (pool < 0)
+					responderr(r);
+				else {
+					fsqprint("p %d\n", pool);
+					respond(r, nil);
+				}
+				return;
+			}
 		}
 	}
 	if (strcmp(argv[0], "b") == 0) {
@@ -393,6 +423,22 @@
 		respond(r, nil);
 		return;
 	}
+	if (strcmp(argv[0], "s") == 0) {
+		if (argc != 4) {
+			respond(r, "bad arguments!");
+			return;
+		}
+		int pool, set, num;
+		pool = atoi(argv[1]);
+		set = atoi(argv[2]);
+		num = atoi(argv[3]);
+		if (!allocdescset(pool, set, num)) {
+			responderr(r);
+			return;
+		}
+		respond(r, nil);
+		return;
+	}
 	
 	respond(r, "error: bad command!");
 }
@@ -402,6 +448,8 @@
 {
 	// c(ompile)
 	// r(un)
+	// b(ind) <pool>
+	
 	Gpufid* f;
 	int i;
 	
@@ -472,6 +520,9 @@
 		s = emalloc(n+1);
 		memmove(s, r->ifcall.data, n);
 		parsecommand(r, s, rootcommand);
+		return;
+	case Qdesc:
+		respond(r, "not supported");
 		return;
 	case Qshader:
 		r->ofcall.count = writeshader(OBJECTID(f), r->ifcall.data, r->ifcall.count, r->ifcall.offset);
--- a/vm.c
+++ b/vm.c
@@ -1,5 +1,6 @@
 #include <u.h>
 #include <libc.h>
+#include <String.h>
 #include "vm.h"
 #include "ops.h"
 #include "objects.h"
@@ -358,6 +359,33 @@
 	memset(descpools[id].sets, 0, sizeof(DescSet)*numsets);
 	
 	return id;
+}
+
+int
+getnumdescpools(void)
+{
+	return numdescpools;
+}
+
+char*
+getpoolinfo(void)
+{
+	String* ret = s_new();
+	char s[128];
+	
+	for (int i = 0; i < numdescpools; i++) {
+		snprint(s, 128, "DescPool %d\n", i);
+		ret = s_append(ret, s);
+		for (int j = 0; j < descpools[i].numsets; j++) {
+			snprint(s, 128, "\tSet %d\n", j);
+			s_append(ret, s);
+			for (int k = 0; k < descpools[i].sets[j].numbindings; k++) {
+				snprint(s, 128, "\t\t%5d %5lld\n", k, descpools[i].sets[j].bindings[k]);
+				s_append(ret, s);
+			}
+		}
+	}
+	return s_to_c(ret);
 }
 
 int
--- a/vm.h
+++ b/vm.h
@@ -30,6 +30,8 @@
 
 // descriptor sets
 int gendescpool(int numsets);
+int getnumdescpools(void);
+char* getpoolinfo(void);
 int allocdescset(int pool, int set, int numbindings);
 int binduniform(vlong id, int pool, int set, int binding);
 int bindshader(vlong id, int pool);