- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.2k
[Merged by Bors] - Reduce branching in TrackedRenderPass #7053
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
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f0fee58
              
                Reduce branching in TrackedRenderPass
              
              
                james7132 0ea8e45
              
                Switch to using RenderContext::begin_tracked_render_pass
              
              
                james7132 28f4ee5
              
                Merge branch 'main' into less-branching-render-pass
              
              
                james7132 2c2f871
              
                Set an artificial limit to avoid overallocating the Vecs
              
              
                james7132 ce58ddf
              
                Update call sites
              
              
                james7132 e525c85
              
                Use wgpu-hal's constants instead of ours.
              
              
                james7132 6a080ec
              
                Merge branch 'main' into less-branching-render-pass
              
              
                james7132 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
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.
I may be missing something, but does this means we always allocate a big buffer for every render pass? Is it small enough that it doesn't matter. The previous impl looked like it would just allocate memory when necessary, if you only need 2-3 bind groups this seems wasteful.
Is it just that the speed up is worth the small memory increase?
Uh oh!
There was an error while loading. Please reload this page.
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.
The latter. The actual size of these Vecs aren't that big (1-2KB at most), and is a static upfront cost compared to the scaling cost of branching on every RenderCommand (not just every entity) that uses it.
The actual limits here are also usually quite small. 16 for both vertex buffers and bind groups, IIRC.
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.
Alright, makes sense then, might be worth adding a small note in a comment I guess, but I'll approve anyway
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.
Some devices may report
u32::MAXfor those limits instead of an actual value, #6841 for example formax_storage_buffers_per_shader_stage. I don't know if that's also the case formax_bind_groupsormax_vertex_buffersbut that's a possibilityThere 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.
After talking about this with cwfitzgerald about this on Discord, it seems like the limits for vertex buffers and bind groups are generally pretty low (max a few hundred). It seems like the limit is hard set in wgpu-hal mostly to avoid reallocations from Vecs.
In the worst case, we should set a reasonable upper limit ourselves (i.e. 1024) which we use
minwith the Device provided limits to be 100% sure it's not overallocating.Original discussion: https://discord.com/channels/691052431525675048/743663924229963868/1059900749636702309
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.
Yeah, after reading the discussion I had the same conclusion.
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.
Ended up using
wgpu-hal's public constantsMAX_VERTEX_BUFFERSandMAX_BIND_GROUPSso we're not keeping them out of sync.