yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// metal-helper-functions.cpp 2#include "metal-helper-functions.h" 3 4#include "metal-device.h" 5#include "metal-util.h" 6 7namespace gfx 8{ 9 10using namespace Slang ; 11 12Result SLANG_MCALL getMetalAdapters (List < AdapterInfo >& outAdapters ) 13{ 14AUTORELEASEPOOL 15 16auto addAdapter = [& ](MTL ::Device * device ) 17 { 18AdapterInfo info = {}; 19const char * name = device -> name ()-> cString (NS ::ASCIIStringEncoding ); 20memcpy (info .name ,name ,Math ::Min (strlen (name ),sizeof (AdapterInfo ::name )- 1 )); 21uint64_t registryID = device -> registryID (); 22memcpy (& info .luid .luid [0 ],& registryID ,sizeof (registryID )); 23outAdapters .add (info ); 24 }; 25 26NS ::Array * devices = MTL ::CopyAllDevices (); 27if (devices -> count ()> 0 ) 28 { 29for (int i = 0 ;i < devices -> count ();++ i ) 30 { 31MTL ::Device * device = static_cast < MTL ::Device *> (devices -> object (i )); 32addAdapter (device ); 33 } 34 } 35else 36 { 37MTL ::Device * device = MTL ::CreateSystemDefaultDevice (); 38addAdapter (device ); 39device -> release (); 40 } 41return SLANG_OK ; 42} 43 44Result SLANG_MCALL createMetalDevice (const IDevice ::Desc * desc ,IDevice ** outRenderer ) 45{ 46RefPtr < metal::DeviceImpl > result = new metal::DeviceImpl (); 47SLANG_RETURN_ON_FAIL (result -> initialize (* desc )); 48returnComPtr (outRenderer ,result ); 49return SLANG_OK ; 50} 51 52}// namespace gfx