Skip to content

Save 25% of memory usage on vertex position buffer (PTex Mesh) - #348

Merged
bigbike merged 5 commits into
masterfrom
pos
Dec 2, 2019
Merged

Save 25% of memory usage on vertex position buffer (PTex Mesh)#348
bigbike merged 5 commits into
masterfrom
pos

Conversation

@bigbike

@bigbike bigbike commented Nov 12, 2019

Copy link
Copy Markdown
Contributor

Motivation and Context

As titled.

Using Vector3 instead of Vector4 for a vertex position in PTex mesh

Reduce memory footprint

How Has This Been Tested

local test with utility viewer.

image

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@bigbike
bigbike requested a review from mosra November 12, 2019 01:58
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Nov 12, 2019
@bigbike

bigbike commented Nov 12, 2019

Copy link
Copy Markdown
Contributor Author

This PR is ready to be reviewed. Thanks.

@erikwijmans

Copy link
Copy Markdown
Contributor

@bigbike

bigbike commented Nov 13, 2019

Copy link
Copy Markdown
Contributor Author

Will the shader need to change here: https://github.com/facebookresearch/habitat-sim/blob/master/src/shaders/ptex-default-gl410.vert#L1 ?

Oh, this is because OpenGL will fill the 4th component, w, with 1.0 automatically for the user if only a 3-dimensional vertex position is provided. I did not realize it would cause confusion here.

If you really feel bad about it, maybe I can change it to vec3. Then the following code will be modified as:

gl_Position = MVP * vec4(position, 1.0);

@mosra: Do you think it is necessary?

@mosra

mosra commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

No, keep the position as vec4. That's what I'm doing for magnum's builtin shaders as well.

}

meshData.vbo.resize(numVertices, vec4f(0, 0, 0, 1));
meshData.vbo.resize(numVertices, vec3f(0, 0, 0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should assert that positionDimensions < 4.

struct MeshData {
std::vector<vec4f> vbo;
std::vector<vec3f> vbo;
std::vector<vec4f> nbo;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't nbo also be a vec3?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As far as I can see, neither nbo nor cbo is used right now (only populated). Is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, neither nbo nor cbo is used right now (only populated). Is that correct?

Yes, you are right. I checked them as well before this PR.

@erikwijmans

Copy link
Copy Markdown
Contributor

Oh, this is because OpenGL will fill the 4th component, w, with 1.0 automatically for the user if only a 3-dimensional vertex position is provided. I did not realize it would cause confusion here.

Ah, I didn't realize OpenGL would do that. How nice of it :)

No need to change it as people will rarely actually look at the shaders themselves, I just wanted to check for my own knowledge.

@msbaines

Copy link
Copy Markdown
Contributor

You may be able to get a really nice speedup if you used the mmapped buffer directly instead of copying vertex attributes a vertex at a time.

@mosra

mosra commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

@msbaines That's precisely what I'm working on to enable with the asset import rework (happening in mosra/magnum#371 -- description might be a bit outdated tho). Together with that we could get rid of all the copies of data stored CPU-side.

@erikwijmans

Copy link
Copy Markdown
Contributor

Together with that we could get rid of all the copies of data stored CPU-side.

For vertices at least, we do need CPU-side copies for #333

@msbaines

Copy link
Copy Markdown
Contributor

Together with that we could get rid of all the copies of data stored CPU-side.

For vertices at least, we do need CPU-side copies for #333

Ah. Very good point. I already broke this once optimizing mesh loading:) You could still keep a CPU-side copy around with mmap. You'd just need to manage the file handle and mapping.

We really need to write tests for this behavior to avoid breaking it.

@codecov-io

codecov-io commented Dec 2, 2019

Copy link
Copy Markdown

Codecov Report

Merging #348 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #348      +/-   ##
==========================================
- Coverage   56.72%   56.71%   -0.01%     
==========================================
  Files         151      151              
  Lines        6740     6741       +1     
==========================================
  Hits         3823     3823              
- Misses       2917     2918       +1
Impacted Files Coverage Δ
src/esp/gfx/PTexMeshShader.h 0% <ø> (ø) ⬆️
src/esp/assets/PTexMeshData.h 0% <ø> (ø) ⬆️
src/esp/assets/PTexMeshData.cpp 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 175ea23...5be86cb. Read the comment docs.

@bigbike
bigbike merged commit 3240b33 into master Dec 2, 2019
@bigbike
bigbike deleted the pos branch December 2, 2019 21:27
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
…ookresearch#348)

* Save 25% of memory usage on vertex position buffer

* minor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants