yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// module.cpp 2#include "vk-module.h" 3 4#include <assert.h> 5#include <stdio.h> 6#include <stdlib.h> 7 8#if SLANG_WINDOWS_FAMILY 9#include <windows.h> 10#else 11#include <dlfcn.h> 12#endif 13 14#include "../renderer-shared.h" 15 16namespace gfx 17{ 18using namespace Slang ; 19 20// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanModule !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 21 22Slang ::Result VulkanModule ::init (bool useSoftwareImpl ) 23{ 24if (isInitialized ()) 25 { 26destroy (); 27 } 28 29const char * dynamicLibraryName = "Unknown" ; 30m_isSoftware = useSoftwareImpl ; 31 32#if SLANG_WINDOWS_FAMILY 33dynamicLibraryName = useSoftwareImpl ?"vk_swiftshader.dll" :"vulkan-1.dll" ; 34HMODULE module = ::LoadLibraryA (dynamicLibraryName ); 35m_module = (void * )module ; 36#elif SLANG_APPLE_FAMILY 37dynamicLibraryName = useSoftwareImpl ?"libvk_swiftshader.dylib" :"libvulkan.1.dylib" ; 38m_module = dlopen (dynamicLibraryName ,RTLD_NOW |RTLD_GLOBAL ); 39#else 40dynamicLibraryName = useSoftwareImpl ?"libvk_swiftshader.so" :"libvulkan.so.1" ; 41if (useSoftwareImpl ) 42 { 43dlopen ("libpthread.so.0" ,RTLD_NOW |RTLD_GLOBAL ); 44 } 45m_module = dlopen (dynamicLibraryName ,RTLD_NOW ); 46#endif 47 48if (!m_module ) 49 { 50return SLANG_FAIL ; 51 } 52 53return SLANG_OK ; 54} 55 56PFN_vkVoidFunction VulkanModule ::getFunction (const char * name )const 57{ 58assert (m_module ); 59if (!m_module ) 60 { 61return nullptr ; 62 } 63#if SLANG_WINDOWS_FAMILY 64return (PFN_vkVoidFunction )::GetProcAddress ((HMODULE )m_module ,name ); 65#else 66return (PFN_vkVoidFunction )dlsym (m_module ,name ); 67#endif 68} 69 70void VulkanModule ::destroy () 71{ 72if (!isInitialized ()) 73 { 74return ; 75 } 76 77#if SLANG_WINDOWS_FAMILY 78 ::FreeLibrary ((HMODULE )m_module ); 79#else 80dlclose (m_module ); 81#endif 82m_module = nullptr ; 83} 84 85}// namespace gfx