maierfelix / webgpu

WebGPU for Node [Deprecated, Unmaintained]
MIT License
244 stars 17 forks source link

How to upload the array of storage buffer block? #13

Closed yyc-git closed 4 years ago

yyc-git commented 4 years ago

Hello!

How to upload the Vertices buffer data in the expected code: ray-closest-hit.rchit:

struct Vertex
{
  vec4 pos;
  ...
};

...

layout(scalar, set = 1, binding = 1) buffer Vertices { Vertex v[]; } vertices[];

...

void main(){
  // objId(uint) is the Object of this instance
  //  ind(ivec3) is the Indices of the triangle

  // Vertex of the triangle
  Vertex v0 = vertices[objId].v[ind.x];
  Vertex v1 = vertices[objId].v[ind.y];
  Vertex v2 = vertices[objId].v[ind.z];
}

to bypass the array of storage buffer block, I store all data in Vertex v[]: ray-closest-hit.rchit:

struct Vertex
{
  vec4 pos;
  ...
};

...

layout(scalar, set = 1, binding = 1) buffer Vertices { Vertex v[]; } vertices;

...

void main(){
  // objId(uint) is the Object of this instance
  //  ind(ivec3) is the Indices of the triangle
  // the indexCount of the triangle is 3

  // Vertex of the triangle
  Vertex v0 = vertices.v[objId * indexCount + ind.x];
  Vertex v1 = vertices.v[objId * indexCount + ind.y];
  Vertex v2 = vertices.v[objId * indexCount + ind.z];
}

Thanks very much!!!

maierfelix commented 4 years ago

Please stop opening up new issues, this most likely isn't a bug. Please do some research before opening issues.