-
Notifications
You must be signed in to change notification settings - Fork 449
[Feature] Use librashader for .slangp (RetroArch) shader support #4678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mr-ke
wants to merge
13
commits into
TASEmulators:master
Choose a base branch
from
mr-ke:feature/librashader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81910d9
[Feature] Use librashader for .slangp (RetroArch) shader support
mr-ke 550c3ce
[lint] address all RunStyleCop format issue
mr-ke fbe5470
[refactor] use DllImport[] than kernel32.dll invocation as project pa…
mr-ke 32dc37e
Simplify conditional in `DisplayConfig.BtnSelectUserFilter_Click`
YoshiRulz 4bdfa93
Further reduce diff in `DisplayConfig`
YoshiRulz 3707e2d
Add missing import
YoshiRulz fad83c6
Simplify conditionals in `DisplayManagerBase.RefreshLibrashader`
YoshiRulz dce8e07
simplify OpenGLTexture2D and OpenGLRenderTarget access by InternalsVi…
mr-ke 00972b7
[refine] utilize PtrToStringUtf8 from BizHawk.Common.Mershul
mr-ke 95b939d
[Feature] Add librashader D3D11 support
mr-ke 662a059
[lint] address SA1124 warnings
mr-ke 0e698fd
[fix] D3D11_CREATE_DEVICE_SINGLETHREADED is needed for librashader D3…
mr-ke f85ad53
[refine] migrate librashader low-level IGL logic to Bizware.Graphics
mr-ke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
src/BizHawk.Client.Common/DisplayManager/Filters/Librashader.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
|
|
||
| using BizHawk.Common; | ||
|
|
||
| namespace BizHawk.Client.Common.Filters | ||
| { | ||
| public static unsafe class Librashader | ||
| { | ||
| private const string DllName = "librashader.dll"; | ||
| private static IntPtr _handle = IntPtr.Zero; | ||
| private static bool _loaded = false; | ||
|
|
||
| public static bool IsLoaded => _loaded; | ||
|
|
||
| public static bool Load() | ||
| { | ||
| if (_loaded) return true; | ||
|
|
||
| Util.DebugWriteLine("[librashader] Attempting to load dll\\librashader.dll..."); | ||
| _handle = LoadLibrary("dll\\librashader.dll"); | ||
| if (_handle == IntPtr.Zero) | ||
| { | ||
| Util.DebugWriteLine("[librashader] Failed to load librashader.dll"); | ||
| return false; | ||
| } | ||
|
|
||
| Util.DebugWriteLine("[librashader] Successfully loaded librashader.dll"); | ||
| _loaded = true; | ||
| LoadFunctions(); | ||
| return true; | ||
| } | ||
|
|
||
| [DllImport("kernel32.dll", SetLastError = true)] | ||
| private static extern IntPtr LoadLibrary(string lpFileName); | ||
|
|
||
| [DllImport("kernel32.dll", SetLastError = true)] | ||
| private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); | ||
|
|
||
| private static T GetDelegate<T>(string name) where T : Delegate | ||
| { | ||
| IntPtr addr = GetProcAddress(_handle, name); | ||
| return addr != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<T>(addr) : null; | ||
| } | ||
|
|
||
| public delegate IntPtr PFN_libra_instance_abi_version(); | ||
| public delegate IntPtr PFN_libra_instance_api_version(); | ||
| public delegate IntPtr PFN_libra_preset_create(byte* filename, out IntPtr preset); | ||
| public delegate int PFN_libra_preset_free(ref IntPtr preset); | ||
| public delegate int PFN_libra_error_free(ref IntPtr error); | ||
| public delegate int PFN_libra_error_print(IntPtr error); | ||
| public delegate int PFN_libra_error_errno(IntPtr error); | ||
|
|
||
| public delegate IntPtr PFN_libra_gl_loader_t(byte* name); | ||
|
|
||
| public delegate IntPtr PFN_libra_gl_filter_chain_create( | ||
| ref IntPtr preset, | ||
| IntPtr loader, | ||
| [In] ref filter_chain_gl_opt_t options, | ||
| out IntPtr chain); | ||
|
|
||
| public delegate int PFN_libra_gl_filter_chain_frame( | ||
| ref IntPtr chain, | ||
| UIntPtr frame_count, | ||
| libra_image_gl_t image, | ||
| libra_image_gl_t output, | ||
| IntPtr viewport, | ||
| IntPtr mvp, | ||
| IntPtr options); | ||
|
|
||
| public delegate int PFN_libra_gl_filter_chain_free(ref IntPtr chain); | ||
|
|
||
| private static PFN_libra_instance_abi_version _instance_abi_version; | ||
| private static PFN_libra_instance_api_version _instance_api_version; | ||
| private static PFN_libra_preset_create _preset_create; | ||
| private static PFN_libra_preset_free _preset_free; | ||
| private static PFN_libra_error_free _error_free; | ||
| private static PFN_libra_error_print _error_print; | ||
| private static PFN_libra_error_errno _error_errno; | ||
| private static PFN_libra_gl_filter_chain_create _gl_filter_chain_create; | ||
| private static PFN_libra_gl_filter_chain_frame _gl_filter_chain_frame; | ||
| private static PFN_libra_gl_filter_chain_free _gl_filter_chain_free; | ||
|
|
||
| internal static PFN_libra_preset_create preset_create => _preset_create; | ||
| internal static PFN_libra_preset_free preset_free => _preset_free; | ||
| internal static PFN_libra_error_print error_print => _error_print; | ||
| internal static PFN_libra_gl_filter_chain_create gl_filter_chain_create => _gl_filter_chain_create; | ||
| internal static PFN_libra_gl_filter_chain_frame gl_filter_chain_frame => _gl_filter_chain_frame; | ||
| internal static PFN_libra_gl_filter_chain_free gl_filter_chain_free => _gl_filter_chain_free; | ||
|
|
||
| private static void LoadFunctions() | ||
| { | ||
| _instance_abi_version = GetDelegate<PFN_libra_instance_abi_version>("libra_instance_abi_version"); | ||
| _instance_api_version = GetDelegate<PFN_libra_instance_api_version>("libra_instance_api_version"); | ||
| _preset_create = GetDelegate<PFN_libra_preset_create>("libra_preset_create"); | ||
| _preset_free = GetDelegate<PFN_libra_preset_free>("libra_preset_free"); | ||
| _error_free = GetDelegate<PFN_libra_error_free>("libra_error_free"); | ||
| _error_print = GetDelegate<PFN_libra_error_print>("libra_error_print"); | ||
| _error_errno = GetDelegate<PFN_libra_error_errno>("libra_error_errno"); | ||
| _gl_filter_chain_create = GetDelegate<PFN_libra_gl_filter_chain_create>("libra_gl_filter_chain_create"); | ||
| _gl_filter_chain_frame = GetDelegate<PFN_libra_gl_filter_chain_frame>("libra_gl_filter_chain_frame"); | ||
| _gl_filter_chain_free = GetDelegate<PFN_libra_gl_filter_chain_free>("libra_gl_filter_chain_free"); | ||
| } | ||
|
|
||
| public static IntPtr PresetCreate(string filename, out IntPtr preset) | ||
| { | ||
| byte[] bytes = Encoding.UTF8.GetBytes(filename + "\0"); | ||
| fixed (byte* ptr = bytes) | ||
| { | ||
| return _preset_create(ptr, out preset); | ||
| } | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public struct filter_chain_gl_opt_t | ||
| { | ||
| public UIntPtr version; | ||
| public ushort glsl_version; | ||
| [MarshalAs(UnmanagedType.U1)] | ||
| public bool use_dsa; | ||
| [MarshalAs(UnmanagedType.U1)] | ||
| public bool force_no_mipmaps; | ||
| [MarshalAs(UnmanagedType.U1)] | ||
| public bool disable_cache; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public struct libra_image_gl_t | ||
| { | ||
| public uint handle; | ||
| public uint format; | ||
| public uint width; | ||
| public uint height; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public struct libra_viewport_t | ||
| { | ||
| public float x; | ||
| public float y; | ||
| public uint width; | ||
| public uint height; | ||
| } | ||
|
|
||
| public static filter_chain_gl_opt_t CreateDefaultOptions() | ||
| { | ||
| return new filter_chain_gl_opt_t | ||
| { | ||
| version = new UIntPtr(1), | ||
| glsl_version = 330, | ||
| use_dsa = false, | ||
| force_no_mipmaps = false, | ||
| disable_cache = false, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.