ref: 2ea9cb1ccca882e47c316cde52302cd108310649
parent: 2456c5671629b47378665485801e73aea7234856
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Feb 17 09:14:02 EST 2024
adds descriptor stuff and ctl object info
--- a/gpufs.c
+++ b/gpufs.c
@@ -184,6 +184,7 @@
//char buf[1024];
//int n;
Gpufid *f;
+ char *s;
f = r->fid->aux;
switch (f->level) {
@@ -207,6 +208,15 @@
r->ofcall.count = readbuffer(OBJECTID(f), r->ofcall.data, r->ifcall.count, r->ifcall.offset);
respond(r, nil);
return;
+ case Qctl:
+ s = getobjectinfo(OBJECTID(f));
+ if (!s) {
+ respond(r, nil);
+ return;
+ }
+ readstr(r, s);
+ respond(r, nil);
+ return;
}
respond(r, "not implemented");
}
@@ -338,6 +348,7 @@
{
// n(ew) s(hader)
// n(ew) b(uffer) <len>
+ // b(ind) <buffer> <pool> <set> <binding>
if (argc <= 0)
return;
@@ -364,6 +375,24 @@
}
}
}
+ if (strcmp(argv[0], "b") == 0) {
+ if (argc != 5) {
+ respond(r, "bad arguments!");
+ return;
+ }
+ vlong buffer;
+ int pool, set, binding;
+ buffer = atoll(argv[1]);
+ pool = atoi(argv[2]);
+ set = atoi(argv[3]);
+ binding = atoi(argv[4]);
+ if (!binduniform(buffer, pool, set, binding)) {
+ responderr(r);
+ return;
+ }
+ respond(r, nil);
+ return;
+ }
respond(r, "error: bad command!");
}
@@ -374,6 +403,7 @@
// c(ompile)
// r(un)
Gpufid* f;
+ int i;
f = r->fid->aux;
@@ -390,6 +420,19 @@
}
if (strcmp(argv[0], "r") == 0) {
respond(r, "not implemented");
+ return;
+ }
+ if (strcmp(argv[0], "b") == 0) {
+ if (argc != 2) {
+ respond(r, "bad command");
+ return;
+ }
+ i = atoi(argv[1]);
+ if (!bindshader(f->id, i)) {
+ responderr(r);
+ return;
+ }
+ respond(r, nil);
return;
}
break;
--- a/vm.c
+++ b/vm.c
@@ -6,6 +6,9 @@
extern int debug;
+static char *Einvalid = "invalid id %lld";
+static char *Ewrongtype = "wrong object type %lld != %s";
+
#define IDVALID(c) (c < numobjects)
Frame *stack = nil;
@@ -76,6 +79,7 @@
struct Object {
int id;
char type;
+ char *info;
union {
Shader s;
Buffer b;
@@ -88,6 +92,48 @@
DescPool descpools[8];
int numdescpools = 0;
+static char* typenames[] = {
+ "BUFFER",
+ "SHADER",
+};
+
+int
+validate(vlong id, int type)
+{
+ if (!IDVALID(id)) {
+ werrstr(Einvalid, id);
+ return 0;
+ }
+ if (objects[id].type != type) {
+ werrstr(Ewrongtype, id, typenames[type]);
+ return 0;
+ }
+ return 1;
+}
+
+void
+updateinfostring(vlong id)
+{
+ switch (objects[id].type) {
+ case SHADER:
+ if (objects[id].info)
+ free(objects[id].info);
+ objects[id].info = smprint(
+ "DescriptorPool %d\n",
+ objects[id].s.descpool
+ );
+ break;
+ case BUFFER:
+ if (objects[id].info)
+ free(objects[id].info);
+ objects[id].info = smprint(
+ "Length %ld\n",
+ objects[id].b.len
+ );
+ break;
+ }
+}
+
vlong
genshader(void)
{
@@ -101,6 +147,7 @@
objects[id].type = SHADER;
objects[id].s.buffer = nil;
objects[id].s.len = -1;
+ updateinfostring(id);
return id;
}
@@ -112,7 +159,7 @@
werrstr("not enough free objects!");
return -1;
}
- id = numobjects;
+ id = numobjects++;
objects[id].id = id;
objects[id].type = BUFFER;
objects[id].b.len = size;
@@ -121,7 +168,7 @@
werrstr("cannot allocate memory: %r");
return -1;
}
- numobjects++;
+ updateinfostring(id);
return id;
}
@@ -174,16 +221,10 @@
{
char *buf;
- if (!IDVALID(id)) {
- werrstr("invalid object id %lld", id);
+ if (!validate(id, SHADER)) {
return 0;
}
- if (objects[id].type != SHADER) {
- werrstr("invalid object type: %lld != SHADER", id);
- return 0;
- }
-
buf = (char*)objects[id].s.buffer;
if (!buf) {
objects[id].s.len = n+offset;
@@ -205,6 +246,7 @@
}
buf += offset;
memcpy(buf, data, n);
+ updateinfostring(id);
return n;
}
@@ -213,16 +255,10 @@
{
char *buf;
- if (!IDVALID(id)) {
- werrstr("invalid object id %lld", id);
+ if (!validate(id, BUFFER)) {
return 0;
}
- if (objects[id].type != BUFFER) {
- werrstr("invalid object type: %lld != BUFFER", id);
- return 0;
- }
-
if (offset+n > objects[id].b.len) {
return -1;
}
@@ -229,6 +265,7 @@
buf = &objects[id].b.buffer[offset];
memcpy(buf, data, n);
+ updateinfostring(id);
return n;
}
@@ -244,16 +281,10 @@
{
char *buf;
- if (!IDVALID(id)) {
- werrstr("invalid id %lld", id);
+ if (!validate(id, SHADER)) {
return 0;
}
- if (objects[id].type != SHADER) {
- werrstr("invalid object type: %lld != SHADER", id);
- return 0;
- }
-
buf = (char*)objects[id].s.buffer;
if (!buf) {
@@ -276,16 +307,10 @@
{
char *buf;
- if (!IDVALID(id)) {
- werrstr("invalid id %lld", id);
+ if (!validate(id, BUFFER)) {
return 0;
}
- if (objects[id].type != BUFFER) {
- werrstr("invalid object type: %lld != BUFFER", id);
- return 0;
- }
-
if (offset+n > objects[id].b.len) {
n = objects[id].b.len - offset;
}
@@ -346,6 +371,10 @@
int
binduniform(vlong id, int pool, int set, int binding)
{
+ if (!validate(id, BUFFER)) {
+ return 0;
+ }
+
if (pool >= numdescpools) {
werrstr("invalid pool id %d", pool);
return 0;
@@ -368,16 +397,21 @@
int
bindshader(vlong id, int pool)
{
- if (!IDVALID(id)) {
- werrstr("invalid id %lld", id);
+ if (!validate(id, SHADER)) {
return 0;
}
- if (objects[id].type != SHADER) {
- werrstr("invalid object type: %lld != SHADER", id);
- return 0;
- }
-
objects[id].s.descpool = pool;
+ updateinfostring(id);
return 1;
+}
+
+char*
+getobjectinfo(vlong id)
+{
+ if (!IDVALID(id)) {
+ werrstr(Einvalid, id);
+ return nil;
+ }
+ return objects[id].info;
}
--- a/vm.h
+++ b/vm.h
@@ -26,6 +26,8 @@
int readshader(vlong id, void *data, long n, long offset);
int readbuffer(vlong id, void *data, long n, long offset);
+char* getobjectinfo(vlong id);
+
// descriptor sets
int gendescpool(int numsets);
int allocdescset(int pool, int set, int numbindings);