ref: 676c163887770438587b64aae2679a93ba836de2
parent: 4974f11f7c2e917de605d02d5c07ad87c241ff80
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Feb 16 06:32:47 EST 2024
adjusts filesystem to display GPU object ids and get rid of Gpuobject fs data type
--- a/gpufs.c
+++ b/gpufs.c
@@ -49,25 +49,14 @@
"shader",
};
-typedef struct Gpuobject Gpuobject;
-struct Gpuobject {
- Ref;
- int type;
- int id;
-};
-
typedef struct Gpufid Gpufid;
struct Gpufid {
int level;
- Gpuobject *object;
+ int id;
};
-static Gpuobject objects[256];
-static int nobjects = 0;
+#define OBJECTID(c) (((Gpufid*)(c))->id)
-#define OBJECTID(c) ((int)(((Gpuobject*)(c)) - objects))
-#define GO(c) ((Gpuobject*)(c))
-
String *fsqueue = nil;
int debug = 0;
@@ -77,21 +66,12 @@
u32int magic = 0x07230203;
-static void
-freeobject(Gpuobject *obj)
-{
- if (obj == nil || decref(obj))
- return;
-
- memset(obj, 0, sizeof(*obj));
-}
-
static void*
wfaux(Gpufid *f)
{
if (f->level < Qobject)
return nil;
- return f->object;
+ return f;
}
static void
@@ -126,32 +106,27 @@
switch (level) {
case Qobject:
- snprint(buf, sizeof(buf), "%d", GO(aux)->id);
+ snprint(buf, sizeof(buf), "%lld", (vlong)aux);
d->name = estrdup(buf);
- break;
+ return;
case Qrctl:
case Qctl:
- d->mode = 0666;
- d->name = estrdup(nametab[level]);
break;
case Qbuffer:
- d->length = getbufferlength(GO(aux)->id);
- d->mode = 0666;
- d->name = estrdup(nametab[level]);
+ d->length = getbufferlength(OBJECTID(aux));
break;
case Qshader:
- d->length = getshaderlength(GO(aux)->id);
- d->mode = 0666;
- d->name = estrdup(nametab[level]);
+ d->length = getshaderlength(OBJECTID(aux));
break;
- default:
- d->name = estrdup(nametab[level]);
}
+ d->mode = 0666;
+ d->name = strdup(nametab[level]);
}
static int
rootgen(int i, Dir *d, void*)
{
+ vlong id;
i += Qroot + 1;
if (i < Qobject) {
fsmkdir(d, i, 0);
@@ -158,8 +133,13 @@
return 0;
}
i -= Qobject;
- if (i < nobjects) {
- fsmkdir(d, Qobject, &objects[i]);
+ if (i < getnumobjects()) {
+ id = getobjectid(i);
+ if (id < 0) {
+ fprint(2, "error: %r\n");
+ return -1;
+ }
+ fsmkdir(d, Qobject, (void*)id);
return 0;
}
return -1;
@@ -168,13 +148,19 @@
static int
objectgen(int i, Dir *d, void *aux)
{
+ Gpufid *f;
i += Qobject + 1;
- fsmkdir(d, i, aux);
+ f = aux;
- // Qshader is last file in list
- if (i >= Qshader)
- return -1;
- return 0;
+ switch (i) {
+ case Qctl:
+ fsmkdir(d, Qctl, aux);
+ return 0;
+ case Qbuffer:
+ fsmkdir(d, getobjecttype(f->id) == BUFFER ? Qbuffer : Qshader, aux);
+ return 0;
+ }
+ return -1;
}
static void
@@ -197,7 +183,7 @@
respond(r, nil);
return;
case Qobject:
- dirread9p(r, objectgen, f->object);
+ dirread9p(r, objectgen, f);
respond(r, nil);
return;
case Qrctl:
@@ -264,7 +250,7 @@
case Qroot:
break;
case Qobject:
- freeobject(f->object);
+ //freeobject(f->object);
break;
default:
f->level = Qobject;
@@ -277,9 +263,10 @@
}
if (i == Qobject) {
j = atoi(name);
- if (j >= 0 && j < nobjects) {
- f->object = &objects[j];
- incref(f->object);
+ if (j >= 0 && j < getnumobjects()) {
+ //f->object = &objects[j];
+ f->id = j;
+ //incref(f->object);
break;
}
}
@@ -306,17 +293,12 @@
if (id < 0) {
return -1;
}
- Gpuobject *o = &objects[nobjects];
- memset(o, 0, sizeof(*o));
- o->type = Qshader;
- o->id = id;
- char *s = smprint("s %d\n", o->id);
+ char *s = smprint("s %d\n", id);
s_append(fsqueue, s);
free(s);
- nobjects++;
- return o->id;
+ return id;
}
static int
@@ -326,17 +308,12 @@
if (id < 0) {
return -1;
}
- Gpuobject *o = &objects[nobjects];
- memset(o, 0, sizeof(*o));
- o->type = Qbuffer;
- o->id = id;
- char *s = smprint("b %d\n", o->id);
+ char *s = smprint("b %d\n", id);
s_append(fsqueue, s);
free(s);
- nobjects++;
- return o->id;
+ return id;
}
static void
@@ -412,7 +389,7 @@
if (f = fid->aux) {
fid->aux = nil;
- freeobject(f->object);
+ //freeobject(f->object);
free(f);
}
}
@@ -427,8 +404,8 @@
return "bad fid";
f = emalloc(sizeof(*f));
memmove(f, o, sizeof(*f));
- if (f->object)
- incref(f->object);
+ //if (f->object)
+ // incref(f->object);
newfid->aux = f;
return nil;
}
--- a/vm.c
+++ b/vm.c
@@ -70,11 +70,6 @@
int compile = 0;
-enum {
- SHADER,
- BUFFER,
-};
-
typedef struct Object Object;
struct Object {
int id;
@@ -144,9 +139,27 @@
long
getshaderlength(int id)
{
+ long len;
if (objects[id].type != SHADER) {
werrstr("invalid object type!");
return -1;
}
- return objects[id].s.len;
+ len = objects[id].s.len;
+ return len < 0 ? 0 : len;
+}
+
+int
+getobjecttype(int id)
+{
+ return objects[id].type;
+}
+
+vlong
+getobjectid(int num)
+{
+ if (num >= numobjects) {
+ werrstr("invalid object number: %d", num);
+ return -1;
+ }
+ return objects[num].id;
}
--- a/vm.h
+++ b/vm.h
@@ -2,9 +2,16 @@
void runstack(u32int *ptr);
void retstack(void);
+enum {
+ BUFFER,
+ SHADER,
+};
+
int genshader(void);
int genbuffer(long size);
int getnumobjects(void);
+vlong getobjectid(int num);
long getshaderlength(int id);
long getbufferlength(int id);
+int getobjecttype(int id);