-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Introduce structs for StorageBufferattribute and StorageInstancedBufferAttribute #29837
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Today I tried to extend the WGSLNodeBuilder.js because the pointer doesn't seem to play a role in the implementation.
For structs we need the following layout in order to be able to use multiple values:
But this currently leads to this error message:
could the reason for this lie in how the compute shader is currently generated?
|
|
||
} | ||
|
||
getWGSLStructString( structName = this.name ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complex snippets are always generated by NodeBuilder
, i.e. WGSLNodeBuilder
in this case.
The default type of TSL should always be defined similar to what we see in GLSL, instead of I think that #29760 (comment) will have less code repetition, and we can use the structure for other purposes as well as const myStruct = struct({
cone_axis: 'vec3',
cone_cutoff: 'float',
error: 'float',
...
});
// buffer size calculated automatically.
const structBuffer = structArray( myStruct, count );
// buffer size calculated manually.
const structBuffer = storageStruct( buffer, myStruct, count ); |
According to your ideas. Wouldn't it be practical if the bufferAttributes carried the struct information (name, type, atomic) for each element? |
I think if we had a Node to take care of the structs it would be better, the other variations could be extended from other nodes and not only attributes, the structure could be used in the return of a function, or in a uniform buffer or TSL |
Then for special cases in which atomic is important, a case distinction would be needed between
Now that I've looked into it a little more closely, the whole thing probably isn't as huge an effort as I thought. I thought I was almost there because I also generated the wgsl code in the WGSLNodeBuilder. You will certainly be able to do the node variant better than me, because I currently don't see how you imagine the connection between the data and the structArray in order to bring it to its destination in the WGSLNodeBuilder. But I'm excited because it's definitely going to be good. This PR is then obsolete. I will then close it later with a reference to yours |
Ahhh, I think I understand you a lot better now. I need some time to understand the code better. We have storage and storageObject. Should storageObject already have been an attempt to implement structs? I ask because when I use storageObject I see in its parameters under node I then managed to get my test compute shader to run
However, only because I deactivated the |
@sunag I think I now largely understand how you imagine it. My test shader now also works according to your scheme. I'll work this out carefully now. |
|
85b3a74
to
5b51d6f
Compare
Related issue: #29760
Description
With this extension the storageBufferAttributes get structs. This means that the information about the data structuring is always directly accessable from the storageBufferAttributes themselves. This seems to me to be a more effective an natural solution than bypass codes, which would have to run through the code in parallel to transport the struct informations about the storageBuffers. This way seems also more robust to me.
But please don't merge yet. I would like to take this PR as an opportunity to include any suggestions for the final improvement. In addition, I haven't yet understood the pointer in the WGSLNodeBuilder sufficiently. Otherwise I would have expanded the WGSLNodeBuilder straight away, because the necessary WGSL code can be generated easily and with little effort using the struct information in the storageBufferAttribute. Type and atomic are optional. The default type is created automatically from itemSize and typeClass if nothing is specified. Based on the comparison of array.count and the length of the structs, the storageBufferAttribute also recognizes whether it is a single struct or a struct array. This is necessary to be able to build the correct wgsl code because of the "array" flag. If the ratio is not an integer, an error message appear. A future struct node, as the top user level, can later take over data creation and struct creation and thus the entries in the storageBufferAttribute and the storageBufferAttribute structs. But it also works very well without a struct node."
toDo: So I still have to learn to understand the pointer in WGSLNodeBuilder.
How to use:
In my example
getWGSLStructString
produce:I can use this string together with the other information from the storageBuffer to build the final WGSL code in the WGSLNodeBuilder, but as mentioned I still have to familiarize myself with the pointer