Hi Aitor,                                                                       
                                                                                
                                                
                                                                                
                                                                                
                                                  
  I've been running the Mesa Zink + KosmicKrisp stack on macOS / Apple          
                                                                                
                                                  
  Silicon (M4 Max) as the OpenGL backend for AAASeed, a real-time C++/Lua
  graphics engine. The stack is working well overall and OpenGL 4.6             
                                                                                
                                                  
  contexts are usable end to end.                                               
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  I have a fix queued locally that I'd like to upstream, but I wanted to        
                                                                                
                                                  
  sync with you first because it touches the KosmicKrisp pipeline state
  machine and I want to make sure my approach is compatible with where          
                                                                                
                                                  
  you want the driver to go.                                                    
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  == Symptom ==                                                                 
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  Apps that mix POINT, LINE and TRIANGLE primitive draw calls on the same       
                                                                                
                                                  
  pipeline produce visual scramble (random vertex positions / wrong
  primitive class rendered). Reproducible with anything non trivial:            
                                                                                
                                                  
  lines from a UI overlay over textured triangles, point sprites, etc.          
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  == Root cause ==                                                              
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  When VkPipeline is created with a single primitive topology, KK ends up       
                                                                                
                                                  
  binding a Metal pipeline whose topology class doesn't match the live
  primitive type at draw time. Metal silently picks something or skips          
                                                                                
                                                  
  pixels depending on the GPU/driver, hence the "scramble".                     
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  == Fix shape ==                                                               
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  I changed `kk_graphics_state` to hold                                         
                                                                                
                                                  
   
      mtl_render_pipeline_state *pipeline_states[4];                            
                                                                                
                                                  
                                                         
  (slots 1=POINT, 2=LINE, 3=TRIANGLE; slot 0 unused for natural indexing        
                                                                                
                                                  
  by mtl_primitive_topology_class).                      
                                                                                
                                                                                
                                                  
  `kk_shader.{c,h}` compiles three pipeline variants up front, one per          
                                                                                
                                                  
  topology class. `kk_flush_draw_state` picks the matching variant per
  draw based on the live primitive topology, so Metal never sees a              
                                                                                
                                                  
  class/primitive mismatch.                                                     
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  Local diff is ~80 lines across `kk_shader.{c,h}`, `kk_cmd_draw.c`,            
                                                                                
                                                  
  `kk_cmd_buffer.h`. I can send it as a patch series for review.
                                                                                
                                                                                
                                                  
  == Questions before sending ==                         
                                                                                
                                                                                
                                                  
  1. Is the "compile 3 variants up front" approach acceptable, or would         
                                                                                
                                                  
     you prefer another option?
                                                                                
                                                                                
                                                  
  2. For dynamic topology (VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY), I treat        
                                                                                
                                                  
     it the same way (variant chosen at flush time). Sounds OK?                 
                                                                                
                                           
                                                                                
                                                                                
                                                  
  3. The diff currently ends + restarts the Metal render encoder when           
                                                                                
                                                  
     the variant changes mid pass. With Apple Silicon's vertex layout           
                                                                                
                                                  
     caches I haven't seen a way to swap pipeline class without that;           
                                                                                
                                                  
     if you know better, I'd love an idea.                                      
                                                                                
                                                
                                                                                
                                                                                
                                                  
  Happy to open an MR straight away if you'd rather review on GitLab.           
                                                                                
                                                  
  Otherwise I can send the patches inline.                                      
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  While I'm here, two trivial unrelated fixes on macOS are already up:          
                                                                                
                                                  
   
    * MR 41359: meson: allow DRI on darwin to enable Zink + EGL builds          
                                                                                
                                                  
    * MR 41360: zink: guard driconf queries with driCheckOption
                                                                                
                                                                                
                                                  
  (plus a third one in flight: zink build-id length fix for Mach-O.)            
                                                                                
                                                  
                                                                                
                                                                                
                                                  
  Thanks for KosmicKrisp, it is just what we needed.                            
                                                                                
               
                                                         
  --                                                                            
                                                                                
                                                  
  Louis Montagne                                         
  [email protected]

Reply via email to