Implement point size emulation in the forward shader for D3D12. #112191
      
        
          +248
        
        
          −44
        
        
          
        
      
    
  
  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.
  
    
  
    
Introduction
This PR adds a point size emulation path in the higher level rendering code to handle D3D12 not supporting it natively.
Implementation Details
Instead of using the point primitive type, two triangles forming a quad are rendered instead. To correctly pass per-point data to each quad, all elements in the mesh's vertex array are modified to have per-instance frequency. The quad itself is procedurally generated in the vertex shader using the vertex index.
Essentially, the draw call changes from:
To:
This also means any shader code that uses vertex or instance indices needs to be adjusted accordingly. This is handled using specialized macros, which change to the following definitions when point size emulation is enabled:
Caveats
These two issues likely could be solved with geometry shaders but Godot has no support for them and they are horribly inefficient.
Notes
From what I've seen, instance frequency is not used anywhere else in Godot, so I want to make sure the changes I made here make sense:
I'm also not entirely sure about the way I'm passing
EMULATE_POINT_SIZEto the shader compiler. Could that cause issues with the shader cache or shader baker?Fixes #106078.