Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various issues around types that are valid in gpu-structs and the ssbo interface #233

Open
stacksmith opened this issue Oct 6, 2019 · 6 comments

Comments

@stacksmith
Copy link
Contributor

Unless I am missing something... int and float works fine, but I want to make structs, man!

(defstruct-g crap  (slota :char )))   Nope.
(defstruct-g crap  (slota :uint16 )))   Nope.
(defstruct-g crap  (slota :uint8 )))   Nope.
(defstruct-g crap  (slota :byte )))   Nope.
(defstruct-g crap  (slota :uchar )))   Nope.

This one made me laugh (cry?) as right next to it I have - with a different syntax for type...

(make-ssbo(setf *gbuf-data* (make-gpu-array nil :dimensions 4096 :element-type :uchar)))
@stacksmith
Copy link
Contributor Author

In the above example - most importantly - you can make an SSBO on a byte array, but then you are thoroughly fucked:

  • Shader uniforms require SSBOs on structures;
  • Can I make a (defstruct-g ssbox (arr (:uchar 4096))) ? Nope. Just like above...
    So I have a bunch of places where I have to create a dummy struct, create an SSBO on it, then stick an array into it - just to pass it to the shader that has to pull out the struct, then pull out the array.
    Thanks.

@stacksmith
Copy link
Contributor Author

stacksmith commented Oct 6, 2019

Actually, it's even worse... The only way I can get an SSBO across:

(defstruct-g ssbox
      (arr (:vec4 380)))
(setf
   *foodata* (make-gpu-array nil :dimensions 1 :element-type 'ssbox)
   *foossbo* (make-ssbo *foodata*))

So, let me get this straight. In order to pass an array, you have to put it into a struct, and then you have to put that struct into an array of 1, stick an SSBO label on it and pass it to a shader?
I am pretty sure that Varjo complained about a struct... I just can't believe that's really how it is...
And of course I am sure you have some magic way of making it all work that I haven't found in the last 48 hours...

@stacksmith
Copy link
Contributor Author

Mo*****er! The above method works, except it's impossible to get to the data! There are 3 indirections:
starting with foodata. So,

(with-gpu-array-as-c-array (foo *foodata*)
	 (ssbox-arr (aref-c foo 0))

And that comes in as a C array; I have no idea if it has anything to do with the GPU array. Shite.

@stacksmith
Copy link
Contributor Author

stacksmith commented Oct 6, 2019

It just gets better! Assuming that the above code is correct, the final dereference requires the actual defstruct-g to get the C array. It seems that there is no with-slots or slot-value in defstruct-g.
That makes things hard as they provide a bit of indirection. Without them we must hardwire slot access, locking into a specific structure.
This means that to cache the data array (so I can actually write to the buffer) at initialization (because it is now about 1K of code just to get to the data and want to get it over with ASAP) - ahm yes, now the I lost genericity of the code that creates and initializes SSBO buffers. That is just crazy, I have many SSBOs, and they are all initialized the same way.
This sucks, because I have some finely factored code that is becoming uglier by the second. I have to pass lambdas around to specialize on these gpu arrays..
Also note that make-ssbo is really particular about the things it can work with. I suppose it fits the rest of the problematic stuff mentioned here.

@stacksmith
Copy link
Contributor Author

stacksmith commented Oct 6, 2019

The fuckery is not over for me. Just as I got comfortable using the C arrays as standins for the GPU arrays, and wrote a fair gob of code, I realized that I am screwed yet another way:

  • I have the SSBO object which is a pointer to an array with a structure containing a GPU array I am interested in. However, I can no longer get it (with my limited understanding of CEPL)... Observe:
F> *gsbuf*
#<SSBO (4) GSSBUF>
F> (ssbo-data *)
#<GPU-ARRAY :element-type GSSBUF :dimensions (1) :backed-by :BUFFER>
F> (with-gpu-array-as-c-array (q *) q)
#<C-ARRAY :element-type GSSBUF :dimensions (1)>
F> (aref-c * 0)
#<GSSBUF {7FCF3D61B000}>    <-----------------This is it!  But... there is no wrapper

#<SB-SYS:SYSTEM-AREA-POINTER {10039DB47F}>
--------------------
The object is an ATOM:
  #.(SB-SYS:INT-SAP #X7FCF3D61B000)

My ass hurts from this treatment.
Added to my collection of useless things: SSBO buffer that cannot be extracted from the structure wrapping it. I really wanted to send the underlying array into a instancing shader and have it automatically feed...

@cbaggers
Copy link
Owner

char isnt a types supported in glsl
uint16 isnt a types supported in glsl
uint8 isnt a types supported in glsl
byte isnt a types supported in glsl
uchar isnt a types supported in glsl

It definitely supports scalar types:

(defstruct-g test-struct-0
  (foo :uint))

in fact when compiling you examples it even suggested scalar types when it couldnt find a glsl type that matched

Varjo: Could not find the correct type for type-spec :UINT8

Perhaps you meant one of these types?:
:uint

It'll take a bit to pick the issues out of this thread. I see some stuff relating to how ssbos are defined which has validity and even tickets already raised on these repos to address them.

@cbaggers cbaggers changed the title DEFSTRUCT-G is unaware of scalar types Various issues around types that are valid in gpu-structs and the ssbo interface Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants