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

InterleavedBuffer: Improve example and docs #12790

Merged
merged 7 commits into from
Dec 12, 2017
Merged

InterleavedBuffer: Improve example and docs #12790

merged 7 commits into from
Dec 12, 2017

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Dec 2, 2017

As the title suggests, a small improvement of docs and example.

@@ -11,21 +11,34 @@
<h1>[name]</h1>

<div class="desc">
"Interleaved" means that multiple types of data (position, color etc.) are packed into a single array buffer.
Organizing geometry data in this way improves memory locality. By keeping vertex data close together, it is more likely
that also caches (e.g. pre-transform vertex cache) store logically related data together. This leads to more cache hits and a better performance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR, but maybe you can rephrase or remove these two sentences...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a suggestion for an alternative? I thought it might be a good Idea to highlight the primary motivation for using interleaved buffers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write it this way:

"Interleaved" means that multiple attributes, possibly of different types, (e.g., position, normal, uv, color) are packed into a single array buffer.

I would leave it at that and avoid a tutorial. Also, avoid making performance claims.

I thought it might be a good Idea to highlight the primary motivation for using interleaved buffers.

What is your reference for the last two sentences? Is that the "primary motivation"?

Copy link
Collaborator Author

@Mugen87 Mugen87 Dec 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, i updated the docs with your suggestion. It's okay for me to exclude the other stuff. (For a moment i forgot to focus just on docs and not tutorials 😇).

What is your reference for the last two sentences? Is that the "primary motivation"?

It is mentioned in this literature , Chapter 3, Interleaving your vertex data for improved performance.

From a performance point of view, the preferred way to organize your vertex data is to interleave the data as an array of structures. This is because you get better memory locality for your vertex data. It is likely that when a vertex shader needs the position of a certain vertex, it will also need the normal and texture coordinates for the same vertex at almost the same time. By keeping these coordinates close together in the memory, it is more likely that when one is read into the pre-transform vertex cache, the others will also be read in the same block and will be available in the pre-transform vertex cache when they are needed by the vertex shader.

Well, "primary motivation" is actually my personal wording 😉 . But i think it's okay to say that performance is the main reason when people interleaving vertex data.

<h2>Constructor</h2>
<h3>[name]( [page:TypedArray array], [page:Integer stride] )</h3>
<div>
[page:TypedArray array] -- A typed array with a shared buffer. Stores the geometry data.<br/>
[page:Integer stride] -- How far apart is the start of each vertex.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How far apart is the start of each vertex

This is worded as a question - can you change it to something like: "The distance between the start of each vertex" or "How far apart the start of each vertex is"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now 😊

</div>

<h3>[property:Integer stride]</h3>
<div>
How far apart is the start of each vertex.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

@looeee looks good?

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 5, 2017

He approved already 😊 #12790 (comment)

@WestLangley
Copy link
Collaborator

I'm still waiting on a reply... The definition of stride in this PR is not correct.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 5, 2017

I'm sry, i've missed that. How about:

The number of items that make up a single amount of vertex data.

@WestLangley
Copy link
Collaborator

Check the WebGL docs for the definition of stride and compare it to our usage. To me, the definition will have to be different. I posted my best guess above.

/ping @benaadams

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 5, 2017

I posted my best guess above.

Sry, but i can't find your guess. Am i blind now?

I would say that the description should be okay now. We are not defining the stride in bytes but in item count. Depending on the type of the item (float, uint8 etc.) we calculate the actual stride via bytesPerElement.

see https://github.com/mrdoob/three.js/blob/dev/src/renderers/WebGLRenderer.js#L914

@benaadams
Copy link
Contributor

Well. its not necessary the amount of vertex data - but how much to jump from the start of one vertex data to get to the next. e.g. the increment you'd have on a for loop in the last position.

@benaadams
Copy link
Contributor

Usually it will be the amount of data per vertex :)

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 5, 2017

I'll pick your definition. I always struggle with this stuff 😅

@WestLangley
Copy link
Collaborator

Whatever I posted is gone... :/

It was something like:

stride = [ the offset in bytes between the beginning of consecutive vertex attributes ] / bytesPerElement;

That means it is unitless.

This definition should be improved further. Maybe someone can come up with something better.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 7, 2017

I vote for merging the PR. We can still add a more precise definition of stride with a separate PR.

@WestLangley
Copy link
Collaborator

I would define InterleavedBuffer.stride like so:

stride - the number of typed-array elements per vertex

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 8, 2017

Great! I'll make a commit 😊

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Dec 8, 2017

Done! 👍

<h2>Constructor</h2>
<h3>[name]( [page:TypedArray array], [page:Integer stride] )</h3>
<div>
[page:TypedArray array] -- A typed array with a shared buffer. Stores the geometry data.<br/>
[page:Integer stride] -- How far apart the start of each vertex is.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How far apart the start of each vertex is.

Can you please check the source code and see if you can verify that the following description is correct?...

The number of elements between the beginning of consecutive vertex attributes.

stride = [ number of bytes between the beginning of consecutive vertex attributes ] / [ bytesPerElement ]

Maybe that description can be reworded, simplified, or corrected, if necessary.

Copy link
Collaborator Author

@Mugen87 Mugen87 Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now i see your original post about stride. I guess you did not submit the review and therefore the post was not visible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mugen87 Yeah, this is all messed up...

var ibp = new THREE.InterleavedBuffer( interleaved_buffer_float32, 4 );
var ibc = new THREE.InterleavedBuffer( interleaved_buffer_uint8, 16 );
var interleavedPositionBuffer = new THREE.InterleavedBuffer( interleavedFloat32Buffer, 4 );
var interleavedColorBuffer = new THREE.InterleavedBuffer( interleavedUint8Buffer, 16 );
Copy link
Collaborator

@WestLangley WestLangley Dec 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not the "position" and "color" buffers. It would be better to call them interleavedBuffer32 and interleavedBuffer8.

That would become more clear if, for example, there was also normal and uv data in addition to position data. That is, if this example had additional Float32 attributes, you would not refer to the buffer as the "position buffer", because it would contain normal and uv data, too.

For sake of clarity, I would use the names I suggested -- or something similar to those.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I'll pick your suggestion!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks!

@WestLangley
Copy link
Collaborator

I think this PR is OK, now.

@mrdoob mrdoob merged commit e0cffb1 into mrdoob:dev Dec 12, 2017
@mrdoob
Copy link
Owner

mrdoob commented Dec 12, 2017

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants