SnowflakePowered / librashader

RetroArch Shaders for All
Mozilla Public License 2.0
77 stars 7 forks source link

[Metal] librashader creating texture exceeding max width #79

Closed jcm93 closed 3 weeks ago

jcm93 commented 1 month ago

Stumbled upon this behavior when doing more ares tests; with the 32X, ares can feed a source texture with a width of 1388 to librashader, which seems like behavior that needs to be rectified on the ares end, but in any case, with a source framebuffer that wide, using certain shaders causes librashader to create textures that exceed the maximum texture width/height in Metal of 16384 = 2^14.

Trace for resize:

Thread 23 Crashed::  Dispatch queue: com.ares.metal-renderer
0   libsystem_kernel.dylib                 0x18393ea60 __pthread_kill + 8
1   libsystem_pthread.dylib                0x183976c20 pthread_kill + 288
2   libsystem_c.dylib                      0x183883a30 abort + 180
3   libsystem_c.dylib                      0x183882d20 __assert_rtn + 284
4   Metal                                  0x18de35194 MTLReportFailure.cold.1 + 48
5   Metal                                  0x18de11db0 MTLReportFailure + 464
6   Metal                                  0x18de07d58 _MTLMessageContextEnd + 876
7   Metal                                  0x18dcd541c -[MTLTextureDescriptorInternal validateWithDevice:] + 2312
8   AGXMetalG13X                           0x1d90188ac -[AGXTexture initWithDevice:desc:isSuballocDisabled:] + 56
9   librashader.dylib                      0x146dab1cc librashader_runtime_mtl::texture::OwnedTexture::new::hee3c3dffbb2dd244 + 468
10  librashader.dylib                      0x146db3938 _$LT$librashader_runtime_mtl..texture..OwnedTexture$u20$as$u20$librashader_runtime..scaling..ScaleFramebuffer$GT$::scale::h0144f4733616fae9 + 416
11  librashader.dylib                      0x146c90958 libra_mtl_filter_chain_frame + 3780
12  ares                                   0x100bf1088 VideoMetal::outputHelper(unsigned int, unsigned int, id<MTLTexture>) + 564
13  libdispatch.dylib                      0x1837c4750 _dispatch_call_block_and_release + 32
14  libdispatch.dylib                      0x1837c63e8 _dispatch_client_callout + 20
15  libdispatch.dylib                      0x1837cda14 _dispatch_lane_serial_drain + 748
16  libdispatch.dylib                      0x1837ce544 _dispatch_lane_invoke + 380
17  libdispatch.dylib                      0x1837d92d0 _dispatch_root_queue_drain_deferred_wlh + 288
18  libdispatch.dylib                      0x1837d8b44 _dispatch_workloop_worker_thread + 404
19  libsystem_pthread.dylib                0x18397300c _pthread_wqthread + 288
20  libsystem_pthread.dylib                0x183971d28 start_wqthread + 8

Repro (in any order):

  1. In ares, launch a Sega 32X / Mega Drive title.
  2. Select crt/crt-maximus-royale.slangp as the shader (probably others affected).
chyyran commented 1 month ago

I could add a check for this but the best I can do would result in a black screen/error return, compared to crashing the thread. If the shade requires a large texture then it probably just wont be compatible with Metal.