diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ab5eb19 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +Assets/TextMesh[[:space:]]Pro/** linguist-vendored +ProjectSettings/** linguist-vendored diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/.envrc b/Packages/com.7thbeat.filebrowser/PluginSource~/.envrc new file mode 100644 index 0000000..e3c2943 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/.envrc @@ -0,0 +1,7 @@ +export DIRENV_WARN_TIMEOUT=20s + +eval "$(devenv direnvrc)" + +# The use_devenv function supports passing flags to the devenv command +# For example: use devenv --impure --option services.postgres.enable:bool true +use devenv diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/.gitignore b/Packages/com.7thbeat.filebrowser/PluginSource~/.gitignore index ea8c4bf..46943fb 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/.gitignore +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/.gitignore @@ -1 +1,11 @@ /target + +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.lock b/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.lock index 8154adf..7c688ad 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.lock +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "ashpd" version = "0.11.0" @@ -188,6 +197,26 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "bindgen" +version = "0.72.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + [[package]] name = "bitflags" version = "2.9.1" @@ -233,6 +262,15 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -245,6 +283,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -295,6 +344,12 @@ dependencies = [ "syn", ] +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "endi" version = "1.1.0" @@ -453,6 +508,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + [[package]] name = "hashbrown" version = "0.15.3" @@ -588,6 +649,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "js-sys" version = "0.3.77" @@ -604,6 +674,16 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +[[package]] +name = "libloading" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" +dependencies = [ + "cfg-if", + "windows-targets", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -643,6 +723,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "nix" version = "0.30.1" @@ -656,6 +742,16 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "normpath" version = "1.3.0" @@ -852,6 +948,12 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "polling" version = "3.7.4" @@ -891,6 +993,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dee91521343f4c5c6a63edd65e54f31f5c92fe8978c40a4282f8372194c6a7d" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro-crate" version = "3.3.0" @@ -959,11 +1071,34 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + [[package]] name = "regex-automata" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rfd" @@ -989,6 +1124,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustix" version = "0.38.44" @@ -1052,6 +1193,12 @@ dependencies = [ "syn", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.5" @@ -1202,9 +1349,19 @@ dependencies = [ "opener", "raw-window-handle", "rfd", + "ufb-native", "windows", ] +[[package]] +name = "ufb-native" +version = "0.1.0" +dependencies = [ + "bindgen", + "libloading", + "pkg-config", +] + [[package]] name = "unicode-ident" version = "1.0.18" diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.toml b/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.toml index 66e1749..d92400c 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.toml +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/Cargo.toml @@ -1,23 +1,3 @@ -[package] -name = "ufb" -version = "0.1.0" -edition = "2024" - -[lib] -name = "ufb" -crate-type = ["rlib", "cdylib"] - -[dependencies] -opener = { version = "0.8.2", features = ["reveal"] } -raw-window-handle = "0.6.2" -rfd = "0.15.3" - -[target.'cfg(target_os = "windows")'.dependencies.windows] -version = "0.61.1" -features = ["Win32_UI_WindowsAndMessaging"] - -[target.'cfg(target_os = "macos")'.dependencies] -objc2 = "0.6.1" -objc2-app-kit = "0.3.1" -# objc2-foundation = "0.3.1" -dispatch2 = "0.3.0" +[workspace] +resolver = "3" +members = ["crates/ufb", "crates/ufb-native"] diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/Cargo.toml b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/Cargo.toml new file mode 100644 index 0000000..05a64f8 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ufb-native" +version = "0.1.0" +edition = "2024" + +build = "build.rs" + +[build-dependencies] +bindgen = "0.72.0" +pkg-config = "0.3.32" + +[dependencies] +libloading = "0.8.8" diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/build.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/build.rs new file mode 100644 index 0000000..6eb5fb3 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/build.rs @@ -0,0 +1,66 @@ +use std::{env, path::PathBuf}; + +#[cfg(not(target_os = "linux"))] +fn main() {} + +#[cfg(target_os = "linux")] +fn main() { + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + + let libs = vec!["x11", "gtk+-3.0", "glib-2.0", "libglvnd"]; + + let mut libs = libs + .into_iter() + .map(|x| pkg_config::probe_library(x).unwrap()) + .map(|x| x.include_paths) + .flatten() + .collect::>(); + + libs.push("include".into()); + + let cflags = libs + .iter() + .map(|x| format!("-I{}", x.to_string_lossy())) + .collect::>(); + + // wrapper.hpp + { + let bindings = bindgen::Builder::default() + .header("wrapper_linux.hpp") + .clang_args(&cflags) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .generate() + .expect("Unable to generate bindings"); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); + } + + // wrapper_gl.hpp + { + let bindings = bindgen::Builder::default() + .header("wrapper_gl.hpp") + .clang_args(&cflags) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .dynamic_library_name("GL") + .generate() + .expect("Unable to generate egl bindings"); + bindings + .write_to_file(out_path.join("bindings_gl.rs")) + .expect("Couldn't write egl bindings!"); + } + + // wrapper_egl.hpp + { + let bindings = bindgen::Builder::default() + .header("wrapper_egl.hpp") + .clang_args(&cflags) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .dynamic_library_name("EGL") + .generate() + .expect("Unable to generate egl bindings"); + bindings + .write_to_file(out_path.join("bindings_egl.rs")) + .expect("Couldn't write egl bindings!"); + } +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityEventQueue.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityEventQueue.h new file mode 100644 index 0000000..d796a65 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityEventQueue.h @@ -0,0 +1,438 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once + +#include "IUnityInterface.h" + +// 5.2 patch 1 + of Unity will support this. +// The lack or presence of this feature can cause the EventQueue +// to crash if used against the wrong version of Unity. +// +// Before we had the IUnityInterfaces system this interface changed +// to support a cleanup handler on events. This broke our plugins +// in older versions of Unity. The registry should help us with +// this sort of thing in the future. +#ifndef EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + #define EVENTQUEUE_SUPPORTS_EVENT_CLEANUP 1 +#endif + +//////////////////////////////////////////////////////////////////////////////////////// +// NOTE: Do not include any additional headers here. This is an external facing header +// so avoid any internal dependencies. +//////////////////////////////////////////////////////////////////////////////////////// +// The Unity EventQueue is a standard way of passing information between plugins or parts +// of the engine without any reliance on managed systems, game objects or +// other pieces of Unity. +// +// Events are simply a structure and GUID pair. GUIDs were chosen rather +// than hashes as it allows plugins to define their own event +// payloads and use the EventQueue. +// +// While the EventQueue itself is self contained and can be used for +// many different applications within Unity the global event +// queue that is passed to plugins is always serviced on the main +// simulation thread and thus serves as a convenient means of +// pushing asynchronous operations back to the main game thread +// +// Payloads should strive to be small. The EventQueue is a 0 allocation +// system which ensures that the use of events does not fragment +// or add undue pressure on resource limited systems. +// +// This header defines ALL that is required to listen, define +// and send events from both within Unity and from plugins. +//////////////////////////////////////////////////////////////////////////////////////// +// USAGE: +// +// SENDING +// ======== +// +// To Define new Event: +// -------------------- +// // Structure and GUID +// struct MyEvent {}; +// REGISTER_EVENT_ID(0x19D736400584B24BULL,0x98B9EFBE26D3F3C9ULL,MyEvent) +// // hash above is a GUID split into 2 64 bit integers for convenience. +// // DO NOT DUPLICATE GUIDS! +// +// To Send an Event: +// ----------------- +// // Create Payload and send +// MyEvent evt; +// GlobalEventQueue::GetInstance ().SendEvent (evt); +// +// LISTENING +// ========== +// +// STATIC FUNCTION: To Listen For An Event: +// ---------------------------------------- +// +// void MyListenFunction (const MyEvent & payload) +// { /* do something useful */ } +// +// // No register that function, create delegate, register delegate with EventQueue +// // Lifetime of delegate is important. +// StaticFunctionEventHandler myEventDelegate (&MyListenFunction); +// GlobalEventQueue::GetInstance ()->AddHandler (&myEventDelegate); +// +// +// CLASS LISTENER: To Listen on an instance of a class: +// ---------------------------------------------------- +// class MyClass +// { +// // This method will get called, always called HandleEvent +// void HandleEvent(const MyEvent & payload); +// +// MyClass() +// { +// // Hookup to listen can be anywhere but here it's in the ctor. +// GlobalEventQueue::GetInstance ()->AddHandler (m_myDelegate.SetObject (this)); +// } +// +// ~MyClass() +// { +// // Stop listening. +// GlobalEventQueue::GetInstance ()->RemoveHandler (m_myDelegate); +// } +// +// // Delegate is a member of the class. +// ClassBasedEventHandler m_myDelegate; +// }; + +// GUID definition for a new event. +// +// There is a tool to compute these, run the tool on the name of your +// message and insert the hash/type combination in your header file. +// This defines the EventId for your event payload (struct) +// Use this for events that do not require a destructor. +#define REGISTER_EVENT_ID(HASHH, HASHL , TYPE) \ +namespace UnityEventQueue \ +{ \ + template<> \ + inline const EventId GetEventId< TYPE > () \ + { \ + return EventId(HASHH,HASHL) ; \ + } \ +} + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP +// GUID definition for a new event with a destructor. +// +// If your event payload requires a destructor. Define: +// +// void Destroy() +// +// Which should be a method on your payload and then use this macro. +// If your event +// can guarantee that someone is listening before you fire +// your first event this is all you have to do. +// +// However if you do not know if someone is listening when you +// fire your first event you will need to call RegisterCleanup +// somewhere to ensure your events get cleaned up properly. +// +// There is a tool to compute these, run the tool on the name of your +// payload and insert the hash/type combination in your header file. +#define REGISTER_EVENT_ID_WITH_CLEANUP(HASHH, HASHL, TYPE) \ +namespace UnityEventQueue \ +{ \ + typedef StaticFunctionEventHandler< TYPE > DestructorMethod_##HASHH##HASHL; \ + \ + template<> \ + inline void GenericDestructorMethodForType< TYPE > ( const TYPE & eventPayload ) \ + { const_cast(eventPayload).Destroy(); } \ + \ + template<> \ + inline EventHandler * GetEventDestructor< TYPE >() \ + { \ + static DestructorMethod_##HASHH##HASHL g_Destructor(&GenericDestructorMethodForType< TYPE >); \ + return &g_Destructor; \ + } \ +} \ +REGISTER_EVENT_ID(HASHH,HASHL,TYPE) + +#endif + +namespace UnityEventQueue +{ + // EventId - GUID + // + // To facilitate custom events the EventId object must be a full fledged GUID + // to ensure cross plugin uniqueness constraints. + // + // Template specialization is used to produce a means of looking up an + // EventId from it's payload type at compile time. The net result should compile + // down to passing around the GUID. + // + // REGISTER_EVENT_ID should be placed in + // the header file of any payload definition OUTSIDE of all namespaces (all EventIds live + // in the UnityEventQueue namespace by default) The payload structure and the registration ID are all that + // is required to expose the event to other systems. + // + // There is a tool to generate registration macros for EventIds. + struct EventId + { + public: + EventId(unsigned long long high, unsigned long long low) + : mGUIDHigh(high) + , mGUIDLow(low) + {} + + EventId(const EventId & other) + { + mGUIDHigh = other.mGUIDHigh; + mGUIDLow = other.mGUIDLow; + } + + EventId & operator=(const EventId & other) + { + mGUIDHigh = other.mGUIDHigh; + mGUIDLow = other.mGUIDLow; + return *this; + } + + bool Equals(const EventId & other) const { return mGUIDHigh == other.mGUIDHigh && mGUIDLow == other.mGUIDLow; } + bool LessThan(const EventId & other) const { return mGUIDHigh < other.mGUIDHigh || (mGUIDHigh == other.mGUIDHigh && mGUIDLow < other.mGUIDLow); } + + unsigned long long mGUIDHigh; + unsigned long long mGUIDLow; + }; + inline bool operator==(const EventId & left, const EventId & right) { return left.Equals(right); } + inline bool operator!=(const EventId & left, const EventId & right) { return !left.Equals(right); } + inline bool operator<(const EventId & left, const EventId & right) { return left.LessThan(right); } + inline bool operator>(const EventId & left, const EventId & right) { return right.LessThan(left); } + inline bool operator>=(const EventId & left, const EventId & right) { return !operator<(left, right); } + inline bool operator<=(const EventId & left, const EventId & right) { return !operator>(left, right); } + // Generic Version of GetEventId to allow for specialization + // + // If you get errors about return values related to this method + // then you have forgotten to include REGISTER_EVENT_ID() for your + // payload / event. This method should never be compiled, ever. + template const EventId GetEventId(); + class EventQueue; + class EventHandler; + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // Generic version retrieving a classes destructor. + // Any class that does not specialize this will not define a destructor. + template EventHandler * GetEventDestructor() { return (EventHandler*)NULL; } + + // This is a static method that helps us call a meaningful method on the event + // itself improving the cleanliness of the EQ design. + template void GenericDestructorMethodForType(const T & /*eventPayload*/) {} +#endif + + // ==================================================================== + // ADAPTER / DELEGATE - This is the base interface that the EventQueue + // uses to know about listeners for events. + // + // DO NOT USE DIRECTLY! + // + // Use the StaticFunction of ClassBased EventHandlers to build + // adapters to your systems and empower them to receive events. + class EventHandler + { + public: + EventHandler() : m_Next(0) {} + virtual ~EventHandler() {} + // This actually kicks the event to the handler function or object. + virtual void HandleEvent(EventId & id, void * data) = 0; + // This is required when registering this handler + virtual EventId HandlerEventId() = 0; +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // This is required when registering this handler + virtual EventHandler * GetMyEventDestructor() = 0; +#endif + // Internal, do not use, required for walking and calling handlers + EventHandler * GetNext() { return m_Next; } + private: + // Intrusive list holding a linked list of handlers for this EventId + // Exists to avoid allocations - Do Not Touch. + friend class EventHandlerList; + EventHandler * m_Next; + }; + + // ==================================================================== + // CLASS DELEGATE - Classes can be the target of events. + // + // Event handlers are the endpoints of the system. To Unity all + // event endpoints look like a single virtual function call. + // + // This adapter will call the HandleEvent( EVENTTYPE & ) method + // on the object specified when an event is triggered. + template + class ClassBasedEventHandler : public EventHandler + { + public: + ClassBasedEventHandler(OBJECTTYPE * handler = NULL) : m_Handler(handler) {} + + // The actual adapter method, calls into the registered object. + virtual void HandleEvent(EventId & id, void * data) + { (void)id; m_Handler->HandleEvent(*static_cast(data)); } + + // Boilerplate required when registering this handler. + virtual EventId HandlerEventId() + { return GetEventId(); } + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // Required boilerplate. Used during registration of this object. + virtual EventHandler * GetMyEventDestructor() + { return GetEventDestructor(); } +#endif + + ClassBasedEventHandler * + SetObject(OBJECTTYPE * handler) + { m_Handler = handler; return this; } + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + OBJECTTYPE * GetHandler() + { return m_Handler; } +#endif + protected: + OBJECTTYPE * m_Handler; + }; + + // ==================================================================== + // FUNCTION DELEGATE - Static functions can be event handlers. + // + // Event handlers are the endpoints of the system. To Unity all + // event endpoints look like a single virtual function call. + // + // This object wraps a static function turning it into an event endpoint + // much like a C# delegate does. + // The wrapped function will be called when the event is triggered + template + class StaticFunctionEventHandler : public EventHandler + { + public: + typedef void (*HandlerFunction)(const EVENTTYPE & payload); + + StaticFunctionEventHandler(HandlerFunction handlerCallback) : m_Handler(handlerCallback) {} + + virtual void HandleEvent(EventId & id, void * data) + { (void)id; m_Handler(*static_cast(data)); } + + // Required boilerplate. Used during registration of this object. + virtual EventId HandlerEventId() + { return GetEventId(); } + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // Required boilerplate. Used during registration of this object. + virtual EventHandler * GetMyEventDestructor() + { return GetEventDestructor(); } +#endif + + protected: + HandlerFunction m_Handler; + }; + + // ============================================================ + // Some built in event types for adding removing event handlers + // from secondary threads. Use these instead of calling AddHandler + // from a secondary thread. + struct AddEventHandler + { + AddEventHandler(EventHandler * handler) : m_Handler(handler) {} + EventHandler * m_Handler; + }; + + struct RemoveEventHandler + { + RemoveEventHandler(EventHandler * handler) : m_Handler(handler) {} + EventHandler * m_Handler; + }; + + // ============================================================ + // The Event Queue is a lock free multiple write single read + // deferred event system. It uses GUIDs to map payloads to + // event handler delegates. The system has some + // templates to make registering for events fairly painless + // but takes care to try to keep template cost very low. + // + // NOTE: payloads should be very very small and never allocate + // or free memory since they can and will be passed across + // dll boundaries. + // + // There is a hard limit of kMaxEventQueueEventSize bytes for any + // payload being passed through this system but payloads that are + // this big are probably being handled improperly. + UNITY_DECLARE_INTERFACE(IUnityEventQueue) + { + public: + // size of 8196 required for PS4 system events + #define kMaxEventQueueEventSize 8196+sizeof(EventId) + + virtual ~IUnityEventQueue() { + } + + // The primary entry point for firing any + // event through the system. The templated + // version is simply syntatic sugar for extracting + // the EventId from the event object. + // + // This can be called from any thread. + template + void SendEvent(T & payload) + { + // Ensure we never fire an event that we can't handle size wise. + Assert(sizeof(T) <= (kMaxEventQueueEventSize - sizeof(EventId))); + + // NOTE: Keep this small to avoid code bloat. + // every line of code in here should be scrutinized + // as this and GetEventId could easily be sources + // of bloat if allowed to grow. + SendEventImpl(UnityEventQueue::GetEventId(), (unsigned char*)(&payload), sizeof(T)); + } + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // Some events want to have a destructor. + // + // You do this by creating a public Destroy() + // method on your Event payload. You then + // register the event with REGISTER_EVENT_ID_WITH_CLEANUP + // + // If your event will have someone listening to it right away + // then you do not need to do anything else. + // + // However, if there is a danger that your event will be fired + // before someone starts listening for it then you must + // call this method somewhere. This will manually register your + // class for cleanup. There is no harm in calling this even + // if it is not required. If in doubt and your event payload + // requires some form of destruction, call this method! + template + void RegisterCleanup(T & payload) + { + EventHandler * eh = UnityEventQueue::GetEventDestructor(); + if (eh != NULL) + SetCleanupImpl(eh); + } + +#endif + + // These are not thread safe and must be done on the same thread + // as the dispatch thread. Doing otherwise risks race conditions. + // Fire the add handler / remove handler event if you need to + // schedule this from a different thread. + virtual void AddHandler(EventHandler * handler) = 0; + virtual void RemoveHandler(EventHandler * handler) = 0; + protected: + virtual void SendEventImpl(EventId id, unsigned char * data, int size) = 0; + +#if EVENTQUEUE_SUPPORTS_EVENT_CLEANUP + // This is an event destructor. You can register one of these + // per event type. This allows events to manage resource if + // they absolutely must. In general you should avoid handling + // resources in events as events usually imply cross thread activity. + virtual void SetCleanupImpl(EventHandler * handler) = 0; +#endif + }; +} + +REGISTER_EVENT_ID(0x19D736400584B24BULL, 0x98B9EFBE26D3F3C9ULL, AddEventHandler) +REGISTER_EVENT_ID(0x8D4A317C4F577F4AULL, 0x851D6E457566A905ULL, RemoveEventHandler) + +UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(0x9959C347F5AE374DULL, 0x9BADE6FC8EF49E7FULL, IUnityEventQueue, UnityEventQueue) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphics.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphics.h new file mode 100644 index 0000000..71dea56 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphics.h @@ -0,0 +1,62 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +// Has to match the GfxDeviceRenderer enum +typedef enum UnityGfxRenderer +{ + //kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed + //kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed + kUnityGfxRendererD3D11 = 2, // Direct3D 11 + kUnityGfxRendererNull = 4, // "null" device (used in batch mode) + kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0 + kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 + //kUnityGfxRendererGXM = 12, // PlayStation Vita, removed + kUnityGfxRendererPS4 = 13, // PlayStation 4 + kUnityGfxRendererXboxOne = 14, // Xbox One + kUnityGfxRendererMetal = 16, // iOS Metal + kUnityGfxRendererOpenGLCore = 17, // OpenGL core + kUnityGfxRendererD3D12 = 18, // Direct3D 12 + kUnityGfxRendererVulkan = 21, // Vulkan + kUnityGfxRendererNvn = 22, // Nintendo Switch NVN API + kUnityGfxRendererXboxOneD3D12 = 23, // MS XboxOne Direct3D 12 + kUnityGfxRendererGameCoreXboxOne = 24, // GameCore Xbox One + kUnityGfxRendererGameCoreXboxSeries = 25, // GameCore XboxSeries + kUnityGfxRendererPS5 = 26, // PS5 + kUnityGfxRendererPS5NGGC = 27 // PS5 NGGC +} UnityGfxRenderer; + +typedef enum UnityGfxDeviceEventType +{ + kUnityGfxDeviceEventInitialize = 0, + kUnityGfxDeviceEventShutdown = 1, + kUnityGfxDeviceEventBeforeReset = 2, + kUnityGfxDeviceEventAfterReset = 3, +} UnityGfxDeviceEventType; + +typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); + +// Should only be used on the rendering thread unless noted otherwise. +UNITY_DECLARE_INTERFACE(IUnityGraphics) +{ + UnityGfxRenderer(UNITY_INTERFACE_API * GetRenderer)(); // Thread safe + + // This callback will be called when graphics device is created, destroyed, reset, etc. + // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, + // when the graphics device is already created. + void(UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); + void(UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); + int(UNITY_INTERFACE_API * ReserveEventIDRange)(int count); // reserves 'count' event IDs. Plugins should use the result as a base index when issuing events back and forth to avoid event id clashes. +}; +UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL, 0x8C5AD4926EB17B11ULL, IUnityGraphics) + + +// Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. +// Provide them with an address to a function of this signature. +typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); +typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data); diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D11.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D11.h new file mode 100644 index 0000000..b94f6ac --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D11.h @@ -0,0 +1,27 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + + +// Should only be used on the rendering thread unless noted otherwise. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11) +{ + ID3D11Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D11Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); + ID3D11Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture); + + ID3D11RenderTargetView* (UNITY_INTERFACE_API * RTVFromRenderBuffer)(UnityRenderBuffer surface); + ID3D11ShaderResourceView* (UNITY_INTERFACE_API * SRVFromNativeTexture)(UnityTextureID texture); + + IDXGISwapChain* (UNITY_INTERFACE_API * GetSwapChain)(); + UINT32(UNITY_INTERFACE_API * GetSyncInterval)(); + UINT(UNITY_INTERFACE_API * GetPresentFlags)(); +}; + +UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL, 0xBF76967F07EFB177ULL, IUnityGraphicsD3D11) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D12.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D12.h new file mode 100644 index 0000000..3dfdccf --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsD3D12.h @@ -0,0 +1,217 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" +#ifndef __cplusplus + #include +#endif + +struct RenderSurfaceBase; +typedef struct RenderSurfaceBase* UnityRenderBuffer; + +typedef struct UnityGraphicsD3D12ResourceState UnityGraphicsD3D12ResourceState; +struct UnityGraphicsD3D12ResourceState +{ + ID3D12Resource* resource; // Resource to barrier. + D3D12_RESOURCE_STATES expected; // Expected resource state before this command list is executed. + D3D12_RESOURCE_STATES current; // State this resource will be in after this command list is executed. +}; + +struct UnityGraphicsD3D12RecordingState +{ + ID3D12GraphicsCommandList* commandList; // D3D12 command list that is currently recorded by Unity +}; + +enum UnityD3D12GraphicsQueueAccess +{ + // No queue acccess, no work must be submitted to UnityD3D12Instance::graphicsQueue from the plugin event callback + kUnityD3D12GraphicsQueueAccess_DontCare, + + // Make sure that Unity worker threads don't access the D3D12 graphics queue + // This disables access to the current Unity command buffer + kUnityD3D12GraphicsQueueAccess_Allow, +}; + +enum UnityD3D12EventConfigFlagBits +{ + kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: (NOT SUPPORTED) + kUnityD3D12EventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set + kUnityD3D12EventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set + kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set) +}; + +struct UnityD3D12PluginEventConfig +{ + UnityD3D12GraphicsQueueAccess graphicsQueueAccess; + UINT32 flags; // UnityD3D12EventConfigFlagBits to be used when invoking a native plugin + bool ensureActiveRenderTextureIsBound; // If true, the actively bound render texture will be bound prior the execution of the native plugin method. +}; + +typedef struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues UnityGraphicsD3D12PhysicalVideoMemoryControlValues; +struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues // all absolute values in bytes +{ + UINT64 reservation; // Minimum required physical memory for an application [default = 64MB]. + UINT64 systemMemoryThreshold; // If free physical video memory drops below this threshold, resources will be allocated in system memory. [default = 64MB] + UINT64 residencyHysteresisThreshold; // Minimum free physical video memory needed to start bringing evicted resources back after shrunken video memory budget expands again. [default = 128MB] + float nonEvictableRelativeThreshold; // The relative proportion of the video memory budget that must be kept available for non-evictable resources. [default = 0.25] +}; + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v7) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + IDXGISwapChain* (UNITY_INTERFACE_API * GetSwapChain)(); + UINT32(UNITY_INTERFACE_API * GetSyncInterval)(); + UINT(UNITY_INTERFACE_API * GetPresentFlags)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); + + void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); + + ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); + + ID3D12Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer rb); + ID3D12Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture); + + // Change the precondition for a specific user-defined event + // Should be called during initialization + void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityD3D12PluginEventConfig * pluginEventConfig); + + bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityGraphicsD3D12RecordingState * outCommandRecordingState); +}; +UNITY_REGISTER_INTERFACE_GUID(0x4624B0DA41B64AACULL, 0x915AABCB9BC3F0D3ULL, IUnityGraphicsD3D12v7) + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v6) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); + + void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); + + ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); + + ID3D12Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer rb); + ID3D12Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture); + + // Change the precondition for a specific user-defined event + // Should be called during initialization + void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityD3D12PluginEventConfig * pluginEventConfig); + + bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityGraphicsD3D12RecordingState* outCommandRecordingState); +}; +UNITY_REGISTER_INTERFACE_GUID(0xA396DCE58CAC4D78ULL, 0xAFDD9B281F20B840ULL, IUnityGraphicsD3D12v6) + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v5) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); + + void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); + + ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); + + ID3D12Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer rb); +}; +UNITY_REGISTER_INTERFACE_GUID(0xF5C8D8A37D37BC42ULL, 0xB02DFE93B5064A27ULL, IUnityGraphicsD3D12v5) + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v4) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); + + void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); + + ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); +}; +UNITY_REGISTER_INTERFACE_GUID(0X498FFCC13EC94006ULL, 0XB18F8B0FF67778C8ULL, IUnityGraphicsD3D12v4) + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v3) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); + + void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); +}; +UNITY_REGISTER_INTERFACE_GUID(0x57C3FAFE59E5E843ULL, 0xBF4F5998474BB600ULL, IUnityGraphicsD3D12v3) + +// Should only be used on the rendering/submission thread. +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v2) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT. + // [Optional] Declares expected and post-execution resource states. + // Returns the fence value. The value will be set once the current frame completes or the GPU is flushed. + UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); +}; +UNITY_REGISTER_INTERFACE_GUID(0xEC39D2F18446C745ULL, 0xB1A2626641D6B11FULL, IUnityGraphicsD3D12v2) + + +// Obsolete +UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12) +{ + ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); + ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); + + ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); + // Returns the value set on the frame fence once the current frame completes or the GPU is flushed + UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); + + // Returns the state a resource will be in after the last command list is executed + bool(UNITY_INTERFACE_API * GetResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES * outState); + // Specifies the state a resource will be in after a plugin command list with resource barriers is executed + void(UNITY_INTERFACE_API * SetResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES state); +}; +UNITY_REGISTER_INTERFACE_GUID(0xEF4CEC88A45F4C4CULL, 0xBD295B6F2A38D9DEULL, IUnityGraphicsD3D12) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsMetal.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsMetal.h new file mode 100644 index 0000000..a57c4ec --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsMetal.h @@ -0,0 +1,117 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +#ifndef __OBJC__ + #error metal plugin is objc code. +#endif +#ifndef __clang__ + #error only clang compiler is supported. +#endif + +@class NSBundle; +@protocol MTLDevice; +@protocol MTLCommandQueue; +@protocol MTLCommandBuffer; +@protocol MTLCommandEncoder; +@protocol MTLTexture; +@class MTLRenderPassDescriptor; + +UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV2) +{ + // V2 + + // Unity has it's own internal logic to happen on command buffer commit, so if you need to commit the current command buffer + // you need to call this function. + // It will just commit the current buffer and returns it (so it can be waited on by the caller code) + id(UNITY_INTERFACE_API * CommitCurrentCommandBuffer)(); + + // returns Unity Metal Command Queue + id(UNITY_INTERFACE_API * CommandQueue)(); + + // V1 + + NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); + id(UNITY_INTERFACE_API * MetalDevice)(); + + id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); + + // for custom rendering support there are two scenarios: + // you want to use current in-flight MTLCommandEncoder (NB: it might be nil) + id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); + // or you might want to create your own encoder. + // In that case you should end unity's encoder before creating your own and end yours before returning control to unity + void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); + + // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder + MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); + + // converting trampoline UnityRenderBufferHandle into native RenderBuffer + UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); + + // access to RenderBuffer's texure + // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr + // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer + // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer + id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); +}; +UNITY_REGISTER_INTERFACE_GUID(0xF58857784FEF46ECULL, 0x9DB7A8803B87DA3DULL, IUnityGraphicsMetalV2) + + +UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV1) +{ + NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); + id(UNITY_INTERFACE_API * MetalDevice)(); + + id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); + + // for custom rendering support there are two scenarios: + // you want to use current in-flight MTLCommandEncoder (NB: it might be nil) + id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); + // or you might want to create your own encoder. + // In that case you should end unity's encoder before creating your own and end yours before returning control to unity + void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); + + // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder + MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); + + // converting trampoline UnityRenderBufferHandle into native RenderBuffer + UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); + + // access to RenderBuffer's texture + // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr + // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer + // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer + id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); +}; +UNITY_REGISTER_INTERFACE_GUID(0x29F8F3D03833465EULL, 0x92138551C15D823DULL, IUnityGraphicsMetalV1) + + +// deprecated: please use versioned interface above + +UNITY_DECLARE_INTERFACE(IUnityGraphicsMetal) +{ + NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); + id(UNITY_INTERFACE_API * MetalDevice)(); + + id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); + id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); + void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); + MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); + + UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); + + id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); + id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); +}; +UNITY_REGISTER_INTERFACE_GUID(0x992C8EAEA95811E5ULL, 0x9A62C4B5B9876117ULL, IUnityGraphicsMetal) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsVulkan.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsVulkan.h new file mode 100644 index 0000000..4cc542d --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityGraphicsVulkan.h @@ -0,0 +1,335 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +#ifndef UNITY_VULKAN_HEADER +#define UNITY_VULKAN_HEADER +#endif + +#include UNITY_VULKAN_HEADER + +struct UnityVulkanInstance +{ + VkPipelineCache pipelineCache; // Unity's pipeline cache is serialized to disk + VkInstance instance; + VkPhysicalDevice physicalDevice; + VkDevice device; + VkQueue graphicsQueue; + PFN_vkGetInstanceProcAddr getInstanceProcAddr; // vkGetInstanceProcAddr of the Vulkan loader, same as the one passed to UnityVulkanInitCallback + unsigned int queueFamilyIndex; + + void* reserved[8]; +}; + +struct UnityVulkanMemory +{ + VkDeviceMemory memory; // Vulkan memory handle + VkDeviceSize offset; // offset within memory + VkDeviceSize size; // size in bytes, may be less than the total size of memory; + void* mapped; // pointer to mapped memory block, NULL if not mappable, offset is already applied, remaining block still has at least the given size. + VkMemoryPropertyFlags flags; // Vulkan memory properties + unsigned int memoryTypeIndex; // index into VkPhysicalDeviceMemoryProperties::memoryTypes + + void* reserved[4]; +}; + +enum UnityVulkanResourceAccessMode +{ + // Does not imply any pipeline barriers, should only be used to query resource attributes + kUnityVulkanResourceAccess_ObserveOnly, + + // Handles layout transition and barriers + kUnityVulkanResourceAccess_PipelineBarrier, + + // Recreates the backing resource (VkBuffer/VkImage) but keeps the previous one alive if it's in use + kUnityVulkanResourceAccess_Recreate, +}; + +struct UnityVulkanImage +{ + UnityVulkanMemory memory; // memory that backs the image + VkImage image; // Vulkan image handle + VkImageLayout layout; // current layout, may change resource access + VkImageAspectFlags aspect; + VkImageUsageFlags usage; + VkFormat format; + VkExtent3D extent; + VkImageTiling tiling; + VkImageType type; + VkSampleCountFlagBits samples; + int layers; + int mipCount; + + void* reserved[4]; +}; + +struct UnityVulkanBuffer +{ + UnityVulkanMemory memory; // memory that backs the buffer + VkBuffer buffer; // Vulkan buffer handle + size_t sizeInBytes; // size of the buffer in bytes, may be less than memory size + VkBufferUsageFlags usage; + + void* reserved[4]; +}; + +struct UnityVulkanRecordingState +{ + VkCommandBuffer commandBuffer; // Vulkan command buffer that is currently recorded by Unity + VkCommandBufferLevel commandBufferLevel; + VkRenderPass renderPass; // Current render pass, a compatible one or VK_NULL_HANDLE + VkFramebuffer framebuffer; // Current framebuffer or VK_NULL_HANDLE + int subPassIndex; // index of the current sub pass, -1 if not inside a render pass + + // Resource life-time tracking counters, only relevant for resources allocated by the plugin + unsigned long long currentFrameNumber; // can be used to track lifetime of own resources + unsigned long long safeFrameNumber; // all resources that were used in this frame (or before) are safe to be released + + void* reserved[4]; +}; + +enum UnityVulkanEventRenderPassPreCondition +{ + // Don't care about the state on Unity's current command buffer + // This is the default precondition + kUnityVulkanRenderPass_DontCare, + + // Make sure that there is currently RenderPass in progress. + // There are no guarantees about the currently bound descriptor sets, vertex buffers, index buffers and pipeline objects + // Unity does however set dynamic pipeline set VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR based on the current settings + // If used in combination with the SRP RenderPass API the resuls is undefined + kUnityVulkanRenderPass_EnsureInside, + + // Make sure that there is currently no RenderPass in progress. + // This allows e.g. resource uploads. + // Ends the current render pass (and resumes it afterwards if needed) + // If used in combination with the SRP RenderPass API the resuls is undefined. + kUnityVulkanRenderPass_EnsureOutside +}; + +enum UnityVulkanGraphicsQueueAccess +{ + // No queue acccess, no work must be submitted to UnityVulkanInstance::graphicsQueue from the plugin event callback + kUnityVulkanGraphicsQueueAccess_DontCare, + + // Make sure that Unity worker threads don't access the Vulkan graphics queue + // This disables access to the current Unity command buffer + kUnityVulkanGraphicsQueueAccess_Allow, +}; + +enum UnityVulkanEventConfigFlagBits +{ + kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: set + kUnityVulkanEventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set + kUnityVulkanEventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set + kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set) +}; + +struct UnityVulkanPluginEventConfig +{ + UnityVulkanEventRenderPassPreCondition renderPassPrecondition; + UnityVulkanGraphicsQueueAccess graphicsQueueAccess; + uint32_t flags; +}; + +// Constant that can be used to reference the whole image +const VkImageSubresource* const UnityVulkanWholeImage = NULL; + +// callback function, see InterceptInitialization +typedef PFN_vkGetInstanceProcAddr(UNITY_INTERFACE_API * UnityVulkanInitCallback)(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void* userdata); + +enum UnityVulkanSwapchainMode +{ + kUnityVulkanSwapchainMode_Default, + kUnityVulkanSwapchainMode_Offscreen +}; + +struct UnityVulkanSwapchainConfiguration +{ + UnityVulkanSwapchainMode mode; +}; + +enum +{ + kUnityVulkanInitCallbackMaxPriority = 0x7FFFFFFF +}; + +UNITY_DECLARE_INTERFACE(IUnityGraphicsVulkanV2) +{ + // Vulkan API hooks + // + // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) + // Unity will call 'func' when initializing the Vulkan API + // The 'getInstanceProcAddr' passed to the callback is the function pointer from the Vulkan Loader + // The function pointer returned from UnityVulkanInitCallback may be a different implementation + // This allows intercepting all Vulkan API calls + // This function is equivalent to calling `AddInterceptInitialization` with a priority of `kUnityVulkanInitCallbackMaxPriority` + // + // Most rules/restrictions for implementing a Vulkan layer apply + // Returns true on success, false on failure (typically because it is used too late) + bool(UNITY_INTERFACE_API * InterceptInitialization)(UnityVulkanInitCallback func, void* userdata); + + // Intercept Vulkan API function of the given name with the given function + // In contrast to InterceptInitialization this interface can be used at any time + // The user must handle all synchronization + // Generally this cannot be used to wrap Vulkan object because there might because there may already be non-wrapped instances + // returns the previous function pointer + PFN_vkVoidFunction(UNITY_INTERFACE_API * InterceptVulkanAPI)(const char* name, PFN_vkVoidFunction func); + + // Change the precondition for a specific user-defined event + // Should be called during initialization + void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityVulkanPluginEventConfig * pluginEventConfig); + + // Access the Vulkan instance and render queue created by Unity + // UnityVulkanInstance does not change between kUnityGfxDeviceEventInitialize and kUnityGfxDeviceEventShutdown + UnityVulkanInstance(UNITY_INTERFACE_API * Instance)(); + + // Access the current command buffer + // + // outCommandRecordingState is invalidated by any resource access calls. + // queueAccess must be kUnityVulkanGraphicsQueueAccess_Allow when called from from a AccessQueue callback or from a event that is configured for queue access. + // Otherwise queueAccess must be kUnityVulkanGraphicsQueueAccess_DontCare. + bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityVulkanRecordingState * outCommandRecordingState, UnityVulkanGraphicsQueueAccess queueAccess); + + // Resource access + // + // Using the following resource query APIs will mark the resources as used for the current frame. + // Pipeline barriers will be inserted when needed. + // + // Resource access APIs may record commands, so the current UnityVulkanRecordingState is invalidated + // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow) + // or from a AccessQueue callback of an event + bool(UNITY_INTERFACE_API * AccessTexture)(void* nativeTexture, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + + bool(UNITY_INTERFACE_API * AccessRenderBufferTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + + bool(UNITY_INTERFACE_API * AccessRenderBufferResolveTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + + bool(UNITY_INTERFACE_API * AccessBuffer)(void* nativeBuffer, VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanBuffer * outBuffer); + + // Control current state of render pass + // + // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow, UnityVulkanGraphicsQueueAccess_FlushAndAllow) + // or from a AccessQueue callback of an event + // See kUnityVulkanRenderPass_EnsureInside, kUnityVulkanRenderPass_EnsureOutside + void(UNITY_INTERFACE_API * EnsureOutsideRenderPass)(); + void(UNITY_INTERFACE_API * EnsureInsideRenderPass)(); + + // Allow command buffer submission to the the Vulkan graphics queue from the given UnityRenderingEventAndData callback. + // This is an alternative to using ConfigureEvent with kUnityVulkanGraphicsQueueAccess_Allow. + // + // eventId and userdata are passed to the callback + // This may or may not be called synchronously or from the submission thread. + // If flush is true then all Unity command buffers of this frame are submitted before UnityQueueAccessCallback + void(UNITY_INTERFACE_API * AccessQueue)(UnityRenderingEventAndData, int eventId, void* userData, bool flush); + + // Configure swapchains that are created by Unity. + // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) + bool(UNITY_INTERFACE_API * ConfigureSwapchain)(const UnityVulkanSwapchainConfiguration * swapChainConfig); + + // see AccessTexture + // Accepts UnityTextureID (UnityRenderingExtTextureUpdateParamsV2::textureID, UnityRenderingExtCustomBlitParams::source) + bool(UNITY_INTERFACE_API * AccessTextureByID)(UnityTextureID textureID, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + + // Vulkan API hooks + // + // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) + // Unity will call 'func' when initializing the Vulkan API + // The 'getInstanceProcAddr' passed to the callback is the function pointer from the Vulkan Loader + // The function pointer returned from UnityVulkanInitCallback may be a different implementation + // This allows intercepting all Vulkan API calls + // The priority is used to sort multiple callbacks such that the highest priority will be called last + // with the original Vulkan loader implementation of vkGetInstanceProcAddress passed in as 'getInstanceProcAddr'. + // A priority value of `kUnityVulkanInitCallbackMaxPriority` is used to force a callback to be called immediately before + // the original Vulkan loader implementation of `vkGetInstanceProcAddress`. Only one callback can be registered with a + // priority of `kUnityVulkanInitCallbackMaxPriority`, if one already exists it will be replaced. + // Passing a priority value of `kUnityVulkanInitCallbackMaxPriority` is equivalent to calling the `InterceptInitialization` method. + // + // Most rules/restrictions for implementing a Vulkan layer apply + // Returns true on success, false on failure (typically because it is used too late) + bool(UNITY_INTERFACE_API * AddInterceptInitialization)(UnityVulkanInitCallback func, void* userdata, int32_t priority); + // Remove vulkan intercept initialization callback. + + // Removal will not take effect until the next time vulkan is initialized. + bool(UNITY_INTERFACE_API * RemoveInterceptInitialization)(UnityVulkanInitCallback func); +}; +UNITY_REGISTER_INTERFACE_GUID(0x329334C09DCA4787ULL, 0xB347DD92A0097FFCULL, IUnityGraphicsVulkanV2) + +UNITY_DECLARE_INTERFACE(IUnityGraphicsVulkan) +{ + // Vulkan API hooks + // + // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) + // Unity will call 'func' when initializing the Vulkan API + // The 'getInstanceProcAddr' passed to the callback is the function pointer from the Vulkan Loader + // The function pointer returned from UnityVulkanInitCallback may be a different implementation + // This allows intercepting all Vulkan API calls + // + // Most rules/restrictions for implementing a Vulkan layer apply + // Returns true on success, false on failure (typically because it is used too late) + bool(UNITY_INTERFACE_API * InterceptInitialization)(UnityVulkanInitCallback func, void* userdata); + // Intercept Vulkan API function of the given name with the given function + // In contrast to InterceptInitialization this interface can be used at any time + // The user must handle all synchronization + // Generally this cannot be used to wrap Vulkan object because there might because there may already be non-wrapped instances + // returns the previous function pointer + PFN_vkVoidFunction(UNITY_INTERFACE_API * InterceptVulkanAPI)(const char* name, PFN_vkVoidFunction func); + // Change the precondition for a specific user-defined event + // Should be called during initialization + void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityVulkanPluginEventConfig * pluginEventConfig); + // Access the Vulkan instance and render queue created by Unity + // UnityVulkanInstance does not change between kUnityGfxDeviceEventInitialize and kUnityGfxDeviceEventShutdown + UnityVulkanInstance(UNITY_INTERFACE_API * Instance)(); + // Access the current command buffer + // + // outCommandRecordingState is invalidated by any resource access calls. + // queueAccess must be kUnityVulkanGraphicsQueueAccess_Allow when called from from a AccessQueue callback or from a event that is configured for queue access. + // Otherwise queueAccess must be kUnityVulkanGraphicsQueueAccess_DontCare. + bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityVulkanRecordingState * outCommandRecordingState, UnityVulkanGraphicsQueueAccess queueAccess); + // Resource access + // + // Using the following resource query APIs will mark the resources as used for the current frame. + // Pipeline barriers will be inserted when needed. + // + // Resource access APIs may record commands, so the current UnityVulkanRecordingState is invalidated + // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow) + // or from a AccessQueue callback of an event + bool(UNITY_INTERFACE_API * AccessTexture)(void* nativeTexture, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + bool(UNITY_INTERFACE_API * AccessRenderBufferTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + bool(UNITY_INTERFACE_API * AccessRenderBufferResolveTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); + bool(UNITY_INTERFACE_API * AccessBuffer)(void* nativeBuffer, VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanBuffer * outBuffer); + // Control current state of render pass + // + // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow, UnityVulkanGraphicsQueueAccess_FlushAndAllow) + // or from a AccessQueue callback of an event + // See kUnityVulkanRenderPass_EnsureInside, kUnityVulkanRenderPass_EnsureOutside + void(UNITY_INTERFACE_API * EnsureOutsideRenderPass)(); + void(UNITY_INTERFACE_API * EnsureInsideRenderPass)(); + // Allow command buffer submission to the the Vulkan graphics queue from the given UnityRenderingEventAndData callback. + // This is an alternative to using ConfigureEvent with kUnityVulkanGraphicsQueueAccess_Allow. + // + // eventId and userdata are passed to the callback + // This may or may not be called synchronously or from the submission thread. + // If flush is true then all Unity command buffers of this frame are submitted before UnityQueueAccessCallback + void(UNITY_INTERFACE_API * AccessQueue)(UnityRenderingEventAndData, int eventId, void* userData, bool flush); + // Configure swapchains that are created by Unity. + // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) + bool(UNITY_INTERFACE_API * ConfigureSwapchain)(const UnityVulkanSwapchainConfiguration * swapChainConfig); + // see AccessTexture + // Accepts UnityTextureID (UnityRenderingExtTextureUpdateParamsV2::textureID, UnityRenderingExtCustomBlitParams::source) + bool(UNITY_INTERFACE_API * AccessTextureByID)(UnityTextureID textureID, const VkImageSubresource * subResource, VkImageLayout layout, + VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); +}; +UNITY_REGISTER_INTERFACE_GUID(0x95355348d4ef4e11ULL, 0x9789313dfcffcc87ULL, IUnityGraphicsVulkan) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityInterface.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityInterface.h new file mode 100644 index 0000000..ab713ec --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityInterface.h @@ -0,0 +1,206 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once + +// Unity native plugin API +// Compatible with C99 + +#if defined(__CYGWIN32__) + #define UNITY_INTERFACE_API __stdcall + #define UNITY_INTERFACE_EXPORT __declspec(dllexport) +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY) + #define UNITY_INTERFACE_API __stdcall + #define UNITY_INTERFACE_EXPORT __declspec(dllexport) +#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(LUMIN) + #define UNITY_INTERFACE_API + #define UNITY_INTERFACE_EXPORT __attribute__ ((visibility ("default"))) +#else + #define UNITY_INTERFACE_API + #define UNITY_INTERFACE_EXPORT +#endif + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// IUnityInterface is a registry of interfaces we choose to expose to plugins. +// +// USAGE: +// --------- +// To retrieve an interface a user can do the following from a plugin, assuming they have the header file for the interface: +// +// IMyInterface * ptr = registry->Get(); +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// Unity Interface GUID +// Ensures global uniqueness. +// +// Template specialization is used to produce a means of looking up a GUID from its interface type at compile time. +// The net result should compile down to passing around the GUID. +// +// UNITY_REGISTER_INTERFACE_GUID should be placed in the header file of any interface definition outside of all namespaces. +// The interface structure and the registration GUID are all that is required to expose the interface to other systems. +struct UnityInterfaceGUID +{ +#ifdef __cplusplus + UnityInterfaceGUID(unsigned long long high, unsigned long long low) + : m_GUIDHigh(high) + , m_GUIDLow(low) + { + } + + UnityInterfaceGUID(const UnityInterfaceGUID& other) + { + m_GUIDHigh = other.m_GUIDHigh; + m_GUIDLow = other.m_GUIDLow; + } + + UnityInterfaceGUID& operator=(const UnityInterfaceGUID& other) + { + m_GUIDHigh = other.m_GUIDHigh; + m_GUIDLow = other.m_GUIDLow; + return *this; + } + + bool Equals(const UnityInterfaceGUID& other) const { return m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow == other.m_GUIDLow; } + bool LessThan(const UnityInterfaceGUID& other) const { return m_GUIDHigh < other.m_GUIDHigh || (m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow < other.m_GUIDLow); } +#endif + unsigned long long m_GUIDHigh; + unsigned long long m_GUIDLow; +}; +#ifdef __cplusplus +inline bool operator==(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.Equals(right); } +inline bool operator!=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !left.Equals(right); } +inline bool operator<(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.LessThan(right); } +inline bool operator>(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return right.LessThan(left); } +inline bool operator>=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator<(left, right); } +inline bool operator<=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator>(left, right); } +#else +typedef struct UnityInterfaceGUID UnityInterfaceGUID; +#endif + + +#ifdef __cplusplus + #define UNITY_DECLARE_INTERFACE(NAME) \ + struct NAME : IUnityInterface + +// Generic version of GetUnityInterfaceGUID to allow us to specialize it +// per interface below. The generic version has no actual implementation +// on purpose. +// +// If you get errors about return values related to this method then +// you have forgotten to include UNITY_REGISTER_INTERFACE_GUID with +// your interface, or it is not visible at some point when you are +// trying to retrieve or add an interface. +template +inline const UnityInterfaceGUID GetUnityInterfaceGUID(); + +// This is the macro you provide in your public interface header +// outside of a namespace to allow us to map between type and GUID +// without the user having to worry about it when attempting to +// add or retrieve and interface from the registry. + #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ + template<> \ + inline const UnityInterfaceGUID GetUnityInterfaceGUID() \ + { \ + return UnityInterfaceGUID(HASHH,HASHL); \ + } + +// Same as UNITY_REGISTER_INTERFACE_GUID but allows the interface to live in +// a particular namespace. As long as the namespace is visible at the time you call +// GetUnityInterfaceGUID< INTERFACETYPE >() or you explicitly qualify it in the template +// calls this will work fine, only the macro here needs to have the additional parameter + #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) \ + const UnityInterfaceGUID TYPE##_GUID(HASHH, HASHL); \ + template<> \ + inline const UnityInterfaceGUID GetUnityInterfaceGUID< NAMESPACE :: TYPE >() \ + { \ + return UnityInterfaceGUID(HASHH,HASHL); \ + } + +// These macros allow for C compatibility in user code. + #define UNITY_GET_INTERFACE_GUID(TYPE) GetUnityInterfaceGUID< TYPE >() + + +#else + #define UNITY_DECLARE_INTERFACE(NAME) \ + typedef struct NAME NAME; \ + struct NAME + +// NOTE: This has the downside that one some compilers it will not get stripped from all compilation units that +// can see a header containing this constant. However, it's only for C compatibility and thus should have +// minimal impact. + #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ + const UnityInterfaceGUID TYPE##_GUID = {HASHH, HASHL}; + +// In general namespaces are going to be a problem for C code any interfaces we expose in a namespace are +// not going to be usable from C. + #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) + +// These macros allow for C compatibility in user code. + #define UNITY_GET_INTERFACE_GUID(TYPE) TYPE##_GUID +#endif + +// Using this in user code rather than INTERFACES->Get() will be C compatible for those places in plugins where +// this may be needed. Unity code itself does not need this. +#define UNITY_GET_INTERFACE(INTERFACES, TYPE) (TYPE*)INTERFACES->GetInterfaceSplit (UNITY_GET_INTERFACE_GUID(TYPE).m_GUIDHigh, UNITY_GET_INTERFACE_GUID(TYPE).m_GUIDLow); + + +#ifdef __cplusplus +struct IUnityInterface +{ +}; +#else +typedef void IUnityInterface; +#endif + + +typedef struct IUnityInterfaces +{ + // Returns an interface matching the guid. + // Returns nullptr if the given interface is unavailable in the active Unity runtime. + IUnityInterface* (UNITY_INTERFACE_API * GetInterface)(UnityInterfaceGUID guid); + + // Registers a new interface. + void(UNITY_INTERFACE_API * RegisterInterface)(UnityInterfaceGUID guid, IUnityInterface * ptr); + + // Split APIs for C + IUnityInterface* (UNITY_INTERFACE_API * GetInterfaceSplit)(unsigned long long guidHigh, unsigned long long guidLow); + void(UNITY_INTERFACE_API * RegisterInterfaceSplit)(unsigned long long guidHigh, unsigned long long guidLow, IUnityInterface * ptr); + +#ifdef __cplusplus + // Helper for GetInterface. + template + INTERFACE* Get() + { + return static_cast(GetInterface(GetUnityInterfaceGUID())); + } + + // Helper for RegisterInterface. + template + void Register(IUnityInterface* ptr) + { + RegisterInterface(GetUnityInterfaceGUID(), ptr); + } + +#endif +} IUnityInterfaces; + + +#ifdef __cplusplus +extern "C" { +#endif + +// If exported by a plugin, this function will be called when the plugin is loaded. +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); +// If exported by a plugin, this function will be called when the plugin is about to be unloaded. +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload(); + +#ifdef __cplusplus +} +#endif + +struct RenderSurfaceBase; +typedef struct RenderSurfaceBase* UnityRenderBuffer; +typedef unsigned int UnityTextureID; diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityLog.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityLog.h new file mode 100644 index 0000000..c537585 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityLog.h @@ -0,0 +1,37 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +/// The type of the log message +enum UnityLogType +{ + /// UnityLogType used for Errors. + kUnityLogTypeError = 0, + /// UnityLogType used for Warnings. + kUnityLogTypeWarning = 2, + /// UnityLogType used for regular log messages. + kUnityLogTypeLog = 3, + /// UnityLogType used for Exceptions. + kUnityLogTypeException = 4, +}; + +#define UNITY_WRAP_CODE(CODE_) do { CODE_; } while (0) +#define UNITY_LOG(PTR_, MSG_) UNITY_WRAP_CODE((PTR_)->Log(kUnityLogTypeLog, MSG_, __FILE__, __LINE__)) +#define UNITY_LOG_WARNING(PTR_, MSG_) UNITY_WRAP_CODE((PTR_)->Log(kUnityLogTypeWarning, MSG_, __FILE__, __LINE__)) +#define UNITY_LOG_ERROR(PTR_, MSG_) UNITY_WRAP_CODE((PTR_)->Log(kUnityLogTypeError, MSG_, __FILE__, __LINE__)) + +UNITY_DECLARE_INTERFACE(IUnityLog) +{ + // Writes information message to Unity log. + // \param type type log channel type which defines importance of the message. + // \param message UTF-8 null terminated string. + // \param fileName UTF-8 null terminated string with file name of the point where message is generated. + // \param fileLine integer file line number of the point where message is generated. + void(UNITY_INTERFACE_API * Log)(UnityLogType type, const char* message, const char *fileName, const int fileLine); +}; +UNITY_REGISTER_INTERFACE_GUID(0x9E7507fA5B444D5DULL, 0x92FB979515EA83FCULL, IUnityLog) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityMemoryManager.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityMemoryManager.h new file mode 100644 index 0000000..04057a0 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityMemoryManager.h @@ -0,0 +1,23 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +#include + +typedef struct PluginAllocator UnityAllocator; + +UNITY_DECLARE_INTERFACE(IUnityMemoryManager) +{ + UnityAllocator* (UNITY_INTERFACE_API * CreateAllocator)(const char* areaName, const char* objectName); + void(UNITY_INTERFACE_API * DestroyAllocator)(UnityAllocator * allocator); + + void* (UNITY_INTERFACE_API * Allocate)(UnityAllocator * allocator, size_t size, size_t align, const char* file, int32_t line); + void(UNITY_INTERFACE_API * Deallocate)(UnityAllocator * allocator, void* ptr, const char* file, int32_t line); + void* (UNITY_INTERFACE_API * Reallocate)(UnityAllocator * allocator, void* ptr, size_t size, size_t align, const char* file, int32_t line); +}; +UNITY_REGISTER_INTERFACE_GUID(0xBAF9E57C61A811ECULL, 0xC5A7CC7861A811ECULL, IUnityMemoryManager) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfiler.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfiler.h new file mode 100644 index 0000000..57d184f --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfiler.h @@ -0,0 +1,493 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +#include + +// Unity Profiler Native plugin API provides an ability to register callbacks for Unity Profiler events. +// The basic functionality includes: +// 1. Ability to create a Unity Profiler Marker. +// 2. Begin and end sample. +// 3. Register a thread for profiling. +// 4. Obtain an information if profiler is available and enabled. +// +// Usage example: +// +// #include +// #include +// +// static IUnityProfiler* s_UnityProfiler = NULL; +// static const UnityProfilerMarkerDesc* s_MyPluginMarker = NULL; +// static bool s_IsDevelopmentBuild = false; +// +// static void MyPluginWorkMethod() +// { +// if (s_IsDevelopmentBuild) +// s_UnityProfiler->BeginSample(s_MyPluginMarker); +// +// // Code I want to see in Unity Profiler as "MyPluginMethod". +// // ... +// +// if (s_IsDevelopmentBuild) +// s_UnityProfiler->EndSample(s_MyPluginMarker); +// } +// +// extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces) +// { +// s_UnityProfiler = unityInterfaces->Get(); +// if (s_UnityProfiler == NULL) +// return; +// s_IsDevelopmentBuild = s_UnityProfiler->IsAvailable() != 0; +// s_UnityProfiler->CreateMarker(&s_MyPluginMarker, "MyPluginMethod", kUnityProfilerCategoryOther, kUnityProfilerMarkerFlagDefault, 0); +// } +// +// extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload() +// { +// } + + +typedef uint32_t UnityProfilerMarkerId; + +enum UnityBuiltinProfilerCategory_ +{ + kUnityProfilerCategoryRender = 0, + kUnityProfilerCategoryScripts = 1, + kUnityProfilerCategoryManagedJobs = 2, + kUnityProfilerCategoryBurstJobs = 3, + kUnityProfilerCategoryGUI = 4, + kUnityProfilerCategoryPhysics = 5, + kUnityProfilerCategoryAnimation = 6, + kUnityProfilerCategoryAI = 7, + kUnityProfilerCategoryAudio = 8, + kUnityProfilerCategoryAudioJob = 9, + kUnityProfilerCategoryAudioUpdateJob = 10, + kUnityProfilerCategoryVideo = 11, + kUnityProfilerCategoryParticles = 12, + kUnityProfilerCategoryGi = 13, + kUnityProfilerCategoryNetwork = 14, + kUnityProfilerCategoryLoading = 15, + kUnityProfilerCategoryOther = 16, + kUnityProfilerCategoryGC = 17, + kUnityProfilerCategoryVSync = 18, + kUnityProfilerCategoryOverhead = 19, + kUnityProfilerCategoryPlayerLoop = 20, + kUnityProfilerCategoryDirector = 21, + kUnityProfilerCategoryVR = 22, + kUnityProfilerCategoryAllocation = 23, kUnityProfilerCategoryMemory = 23, + kUnityProfilerCategoryInternal = 24, + kUnityProfilerCategoryFileIO = 25, + kUnityProfilerCategoryUISystemLayout = 26, + kUnityProfilerCategoryUISystemRender = 27, + kUnityProfilerCategoryVFX = 28, + kUnityProfilerCategoryBuildInterface = 29, + kUnityProfilerCategoryInput = 30, + kUnityProfilerCategoryVirtualTexturing = 31, + kUnityProfilerCategoryGPU = 32, + kUnityProfilerCategoryPhysics2D = 33, + kUnityProfilerCategoryNetworkOperations = 34, + kUnityProfilerCategoryUIDetails = 35, + kUnityProfilerCategoryDebug = 36, + kUnityProfilerCategoryJobs = 37, +}; +typedef uint16_t UnityProfilerCategoryId; + +typedef struct UnityProfilerCategoryDesc +{ + // Incremental category index. + UnityProfilerCategoryId id; + // Reserved. + uint16_t reserved0; + // Internally associated category color which is in 0xRRGGBBAA format. + uint32_t rgbaColor; + // NULL-terminated string which is associated with the category. + const char* name; +} UnityProfilerCategoryDesc; + +enum UnityProfilerMarkerFlag_ +{ + kUnityProfilerMarkerFlagDefault = 0, + + kUnityProfilerMarkerFlagScriptUser = 1 << 1, // Markers created with C# API. + kUnityProfilerMarkerFlagScriptInvoke = 1 << 5, // Runtime invocations with ScriptingInvocation::Invoke. + kUnityProfilerMarkerFlagScriptEnterLeave = 1 << 6, // Deep profiler. + + kUnityProfilerMarkerFlagAvailabilityEditor = 1 << 2, // Editor-only marker, doesn't present in dev and non-dev players. + kUnityProfilerMarkerFlagAvailabilityNonDev = 1 << 3, // Non-development marker, is present everywhere including release builds. + + kUnityProfilerMarkerFlagWarning = 1 << 4, // Indicates undesirable, performance-wise suboptimal code path. + + kUnityProfilerMarkerFlagCounter = 1 << 7, // Marker is also used as a counter. + + kUnityProfilerMarkerFlagVerbosityDebug = 1 << 10, // Internal debug markers - e.g. JobSystem Idle. + kUnityProfilerMarkerFlagVerbosityInternal = 1 << 11, // Internal markers - e.g. Mutex/semaphore waits. + kUnityProfilerMarkerFlagVerbosityAdvanced = 1 << 12 // Markers which are useful for advanced users - e.g. Loading. +}; +typedef uint16_t UnityProfilerMarkerFlags; + +enum UnityProfilerMarkerEventType_ +{ + kUnityProfilerMarkerEventTypeBegin = 0, + kUnityProfilerMarkerEventTypeEnd = 1, + kUnityProfilerMarkerEventTypeSingle = 2 +}; +typedef uint16_t UnityProfilerMarkerEventType; + +typedef struct UnityProfilerMarkerDesc +{ + // Per-marker callback chain pointer. Don't use. + const void* callback; + // Event id. + UnityProfilerMarkerId id; + // UnityProfilerMarkerFlag_ value. + UnityProfilerMarkerFlags flags; + // Category index the marker belongs to. + UnityProfilerCategoryId categoryId; + // NULL-terminated string which is associated with the marker. + const char* name; + // Metadata descriptions chain. Don't use. + const void* metaDataDesc; +} UnityProfilerMarkerDesc; + +enum UnityProfilerMarkerDataType_ +{ + kUnityProfilerMarkerDataTypeNone = 0, + kUnityProfilerMarkerDataTypeInstanceId = 1, + kUnityProfilerMarkerDataTypeInt32 = 2, + kUnityProfilerMarkerDataTypeUInt32 = 3, + kUnityProfilerMarkerDataTypeInt64 = 4, + kUnityProfilerMarkerDataTypeUInt64 = 5, + kUnityProfilerMarkerDataTypeFloat = 6, + kUnityProfilerMarkerDataTypeDouble = 7, + kUnityProfilerMarkerDataTypeString = 8, + kUnityProfilerMarkerDataTypeString16 = 9, + kUnityProfilerMarkerDataTypeBlob8 = 11, + kUnityProfilerMarkerDataTypeGfxResourceId = 12, + kUnityProfilerMarkerDataTypeCount // Total count of data types +}; +typedef uint8_t UnityProfilerMarkerDataType; + +enum UnityProfilerMarkerDataUnit_ +{ + kUnityProfilerMarkerDataUnitUndefined = 0, + kUnityProfilerMarkerDataUnitTimeNanoseconds = 1, + kUnityProfilerMarkerDataUnitBytes = 2, + kUnityProfilerMarkerDataUnitCount = 3, + kUnityProfilerMarkerDataUnitPercent = 4, + kUnityProfilerMarkerDataUnitFrequencyHz = 5, +}; +typedef uint8_t UnityProfilerMarkerDataUnit; + +typedef struct UnityProfilerMarkerData +{ + UnityProfilerMarkerDataType type; + uint8_t reserved0; + uint16_t reserved1; + uint32_t size; + const void* ptr; +} UnityProfilerMarkerData; + +enum UnityProfilerFlowEventType_ +{ + // Starts flow chain for a current profiler marker scope (__enclosing__ scope). + // Mark the scheduler function with "begin" flow to connect it later to execution function on another thread. + kUnityProfilerFlowEventTypeBegin = 0, + // The flow continues with the next sample. + // Marks the __next__ profiler sample connected to the sample which started the flow (kUnityProfilerFlowEventTypeBegin) or previous (in time) kUnityProfilerFlowEventTypeNext flow event. + // All parallel flow instances are equivalent and connected to the same previous in time kUnityProfilerFlowEventTypeBegin or kUnityProfilerFlowEventTypeNext events and next (also in time) kUnityProfilerFlowEventTypeNext event. + kUnityProfilerFlowEventTypeParallelNext = 1, + // Ends flow started by kUnityProfilerFlowEventTypeBegin. Usually represents a sync point (SyncFence) + // Marks the __enclosing__ sample as endpoint. + kUnityProfilerFlowEventTypeEnd = 2, + // The flow continues with the next sample. + // Marks the __next__ profiler sample connected to the sample which started the flow (kUnityProfilerFlowEventTypeBegin). + kUnityProfilerFlowEventTypeNext = 3, +}; +typedef uint8_t UnityProfilerFlowEventType; + +enum UnityProfilerCounterFlags_ +{ + kUnityProfilerCounterFlagNone = 0, + // Automatic flush of counter value to recorder or profiler at the end of a frame + kUnityProfilerCounterFlushOnEndOfFrame = 1 << 1, + // Automatic reset counter value to zero on flush + kUnityProfilerCounterFlagResetToZeroOnFlush = 1 << 2, + // Use atomic to access counters value. Don't use + kUnityProfilerCounterFlagAtomic = 1 << 3, + // Pull-style counter. Don't use + kUnityProfilerCounterFlagGetter = 1 << 4 +}; +typedef uint16_t UnityProfilerCounterFlags; + + +typedef uint64_t UnityProfilerThreadId; + +typedef void (*UnityProfilerCounterStatePtrCallback)(void* userData); + +#ifdef __cplusplus +template struct UnityProfilerDataUnitHelper; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeInt32; } }; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeUInt32; } }; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeInt64; } }; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeUInt64; } }; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeFloat; } }; +template<> struct UnityProfilerDataUnitHelper { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeDouble; } }; + +template struct UnityProfilerCounter; +#endif + +// Available since 2021.2 +UNITY_DECLARE_INTERFACE(IUnityProfilerV2) +{ + void BeginSample(const UnityProfilerMarkerDesc * markerDesc) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, 0, NULL); + } + + void BeginSample(const UnityProfilerMarkerDesc * markerDesc, uint16_t eventDataCount, const UnityProfilerMarkerData * eventData) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, eventDataCount, eventData); + } + + void EndSample(const UnityProfilerMarkerDesc * markerDesc) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeEnd, 0, NULL); + } + + // Create instrumentation event. + // \param markerDesc is a pointer to marker description struct. + // \param eventType is an event type - UnityProfilerMarkerEventType_. + // \param eventDataCount is an event metadata count passed in eventData. Must be less than eventDataCount specified in CreateMarker. + // \param eventData is a metadata array of eventDataCount elements. + void(UNITY_INTERFACE_API * EmitEvent)(const UnityProfilerMarkerDesc * markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData * eventData); + + // Returns 1 if Unity Profiler is enabled, 0 overwise. + int(UNITY_INTERFACE_API * IsEnabled)(); + + // Returns 1 if Unity Profiler is available, 0 overwise. + // Profiler is available only in Development builds. Release builds have Unity Profiler compiled out. + // However individual markers can be available even in Release builds (e.g. GC.Collect) and be collected with + // Recorder API or forwarded to platform and other profilers (via IUnityProfilerCallbacks::RegisterMarkerEventCallback API). + // You can choose whenever you want or not emit profiler event in Development and Release builds using the cached result of this method. + int(UNITY_INTERFACE_API * IsAvailable)(); + + // Creates a new Unity Profiler marker. + // \param desc Pointer to the const UnityProfilerMarkerDesc* which is set to the created marker in a case of a succesful execution. + // \param name Marker name to be displayed in Unity Profiler. + // \param flags Marker flags. One of UnityProfilerMarkerFlag_ enum. Use kUnityProfilerMarkerFlagDefault if not sure. + // \param eventDataCount Maximum count of potential metadata parameters count. + // \return 0 on success and non-zero in case of error. + int(UNITY_INTERFACE_API * CreateMarker)(const UnityProfilerMarkerDesc * *desc, const char* name, UnityProfilerCategoryId category, UnityProfilerMarkerFlags flags, int eventDataCount); + + // Set a metadata description for the Unity Profiler marker. + // \param markerDesc is a pointer to marker description struct. + // \param index metadata index to set name for. + // \param metadataType Data type. Must be of UnityProfilerMarkerDataType_ enum. + // \param name Metadata name. + // \return 0 on success and non-zero in case of error. + int(UNITY_INTERFACE_API * SetMarkerMetadataName)(const UnityProfilerMarkerDesc * desc, int index, const char* metadataName, UnityProfilerMarkerDataType metadataType, UnityProfilerMarkerDataUnit metadataUnit); + + // Creates a new Unity Profiler category. + // \param category is a pointer to UnityProfilerCategoryId variable which is set to the created category id in case of a succesful execution. + // \param name Category name to be displayed in Unity Profiler. + // \return 0 on success and non-zero in case of error. + int(UNITY_INTERFACE_API * CreateCategory)(UnityProfilerCategoryId *category, const char* name, uint32_t unused); + + // Registers current thread with Unity Profiler. + // Has no effect in Release Players. + // \param threadId Optional Unity Profiler thread identifier which it written on successful method call. Can be used with UnregisterThread. + // \param groupName Thread group name. Unity Profiler aggregates threads with the same group. + // \param name Thread name. + // \return 0 on success and non-zero in case of error. + int(UNITY_INTERFACE_API * RegisterThread)(UnityProfilerThreadId * threadId, const char* groupName, const char* name); + + // Unregisters current thread from Unity Profiler and cleans up all associated memory. + // Has no effect in Release Players. + // \param threadId Unity Profiler thread identifier obtained with RegisterThread call. Use 0 to cleanup the current thread. + // \return 0 on success and non-zero in case of error. + int(UNITY_INTERFACE_API * UnregisterThread)(UnityProfilerThreadId threadId); + +#ifdef __cplusplus + // Creates a new Unity Profiler counter wrapper object. + // \param category Counter marker category which assignes marker to one of visualized groups on the profiler chart. + // \param name Counter marker name to be displayed in Unity Profiler. + // \param valueUnit Data unit, defines how data will be visualized. Must be of UnityProfilerMarkerDataUnit_ enum. + // \param activateFunc Callback called when new coutner data receiver is connected. + // \param deactivateFunc Callback called when coutner data receiver is disconnected. + // \param userData User data pointer passed to activate and deactivate callbacks. + // \return UnityProfilerCounter counter struct. + template + UnityProfilerCounter CreateCounter(UnityProfilerCategoryId category, const char* name, UnityProfilerMarkerDataUnit dataUnit, + UnityProfilerCounterStatePtrCallback activateFunc = nullptr, UnityProfilerCounterStatePtrCallback deactivateFunc = nullptr, void* userData = nullptr) + { + return UnityProfilerCounter( + this, + this->CreateCounterValue( + category, + name, + kUnityProfilerMarkerFlagCounter, + UnityProfilerDataUnitHelper::GetProfilerType(), + dataUnit, + sizeof(T), + kUnityProfilerCounterFlagNone, + activateFunc, + deactivateFunc, + userData + ) + ); + } + +#endif + + // Creates a new Unity Profiler counter. + // \param category Counter marker category which assignes marker to one of visualized groups on the profiler chart. + // \param name Counter marker name to be displayed in Unity Profiler. + // \param flags Counter marker flags. One of UnityProfilerMarkerFlag_ enum. Use kUnityProfilerMarkerFlagDefault if not sure. + // \param valueType Data type. Must be of UnityProfilerMarkerDataType_ enum. + // \param valueUnit Data unit, defines how data will be visualized. Must be of UnityProfilerMarkerDataUnit_ enum. + // \param valueSize Data size, must be less or equal to 8. + // \param counterFlags Counter flags. One of UnityProfilerCounterFlags_ enum. Use kUnityProfilerCounterFlagNone if not sure. + // \param activateFunc Callback called when new coutner data receiver is connected. + // \param deactivateFunc Callback called when coutner data receiver is disconnected. + // \param userData User data pointer passed to activate and deactivate callbacks. + // \return CounterValue object address on success and null in case of error. + void* (UNITY_INTERFACE_API* CreateCounterValue)( + UnityProfilerCategoryId category, + const char* name, + UnityProfilerMarkerFlags flags, + UnityProfilerMarkerDataType valueType, + UnityProfilerMarkerDataUnit valueUnit, + size_t valueSize, + UnityProfilerCounterFlags counterFlags, + UnityProfilerCounterStatePtrCallback activateFunc, + UnityProfilerCounterStatePtrCallback deactivateFunc, + void* userData + ); + + void(UNITY_INTERFACE_API * FlushCounterValue)(void* counter); +}; +UNITY_REGISTER_INTERFACE_GUID(0xB957E0189CB6A30BULL, 0x83CE589AE85B9068ULL, IUnityProfilerV2) + +#ifdef __cplusplus +struct UnityProfilerCounterValue +{ + UnityProfilerCounterValue() + : m_Profiler(nullptr) + , m_Value(nullptr) + { + } + + UnityProfilerCounterValue(IUnityProfilerV2* profiler, void* value) + : m_Profiler(profiler) + , m_Value(value) + { + } + + template + inline T& Value() { return *static_cast(m_Value); } + + template + inline const T& Value() const { return *static_cast(m_Value); } + + inline void Flush() + { + m_Profiler->FlushCounterValue(m_Value); + } + +private: + void* m_Value; + IUnityProfilerV2* m_Profiler; +}; + +template +struct UnityProfilerCounter : public UnityProfilerCounterValue +{ + UnityProfilerCounter() {} + UnityProfilerCounter(IUnityProfilerV2* profiler, void* value) : UnityProfilerCounterValue(profiler, value) {} + + T& operator*() { return Value(); } + const T& operator*() const { return Value(); } + + operator T&() { return Value(); } + operator T() const { return Value(); } + + T& operator=(const T& s) + { + Value() = s; + return Value(); + } + + T operator++(int) + { + T copy(Value()); + ++(Value()); + return copy; + } + + UnityProfilerCounter& operator++() + { + ++(Value()); + return *this; + } + + T operator--(int) + { + T copy(Value()); + --(Value()); + return copy; + } + + UnityProfilerCounter& operator--() + { + --(Value()); + return *this; + } + + UnityProfilerCounter& operator-=(T& s) + { + (Value()) -= s; + return *this; + } + + UnityProfilerCounter& operator+=(T& s) + { + (Value()) += s; + return *this; + } +}; +#endif + +// Available since 2020.1 +UNITY_DECLARE_INTERFACE(IUnityProfiler) +{ + void BeginSample(const UnityProfilerMarkerDesc* markerDesc) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, 0, NULL); + } + + void BeginSample(const UnityProfilerMarkerDesc* markerDesc, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, eventDataCount, eventData); + } + + void EndSample(const UnityProfilerMarkerDesc* markerDesc) + { + (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeEnd, 0, NULL); + } + + void(UNITY_INTERFACE_API * EmitEvent)(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData); + + int(UNITY_INTERFACE_API * IsEnabled)(); + int(UNITY_INTERFACE_API * IsAvailable)(); + + int(UNITY_INTERFACE_API * CreateMarker)(const UnityProfilerMarkerDesc** desc, const char* name, UnityProfilerCategoryId category, UnityProfilerMarkerFlags flags, int eventDataCount); + int(UNITY_INTERFACE_API * SetMarkerMetadataName)(const UnityProfilerMarkerDesc* desc, int index, const char* metadataName, UnityProfilerMarkerDataType metadataType, UnityProfilerMarkerDataUnit metadataUnit); + + int(UNITY_INTERFACE_API * RegisterThread)(UnityProfilerThreadId* threadId, const char* groupName, const char* name); + int(UNITY_INTERFACE_API * UnregisterThread)(UnityProfilerThreadId threadId); +}; +UNITY_REGISTER_INTERFACE_GUID(0x2CE79ED8316A4833ULL, 0x87076B2013E1571FULL, IUnityProfiler) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfilerCallbacks.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfilerCallbacks.h new file mode 100644 index 0000000..6cb08e9 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityProfilerCallbacks.h @@ -0,0 +1,174 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" +#include "IUnityProfiler.h" + +#include + +// Unity Profiler Callbacks native plugin API provides an ability to register callbacks for Unity Profiler events. +// The basic functionality includes: +// 1. Profiler category creation callback - provides information about category name and color. +// 2. Profiler marker creation callback - provides information about new marker which is created internally or with C# API. +// 3. Marker event callback - allows to intercept begin/end events for the particular marker. +// 4. Frame event callback - provides information about logical CPU frame. +// +// Usage example: +// +// #include +// #include +// +// static IUnityProfilerCallbacks* s_UnityProfilerCallbacks = NULL; +// +// static void UNITY_INTERFACE_API MyProfilerEventCallback(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, unsigned short eventDataCount, const UnityProfilerMarkerData* eventData, void* userData) +// { +// switch (eventType) +// { +// case kUnityProfilerMarkerEventTypeBegin: +// { +// MyProfilerPushMarker(markerDesc->name); +// break; +// } +// case kUnityProfilerMarkerEventTypeEnd: +// { +// MyProfilerPopMarker(markerDesc->name); +// break; +// } +// } +// } +// +// static void UNITY_INTERFACE_API MyProfilerCreateMarkerCallback(const UnityProfilerMarkerDesc* markerDesc, void* userData) +// { +// s_UnityProfilerCallbacks->RegisterMarkerEventCallback(markerDesc, MyProfilerEventCallback, NULL); +// } +// +// extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces) +// { +// s_UnityProfilerCallbacks = unityInterfaces->Get(); +// s_UnityProfilerCallbacks->RegisterCreateMarkerCallback(&MyProfilerCreateMarkerCallback, NULL); +// } +// +// extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload() +// { +// s_UnityProfilerCallbacks->UnregisterCreateMarkerCallback(&MyProfilerCreateMarkerCallback, NULL); +// s_UnityProfilerCallbacks->UnregisterMarkerEventCallback(NULL, &MyProfilerEventCallback, NULL); +// } + +typedef struct UnityProfilerThreadDesc +{ + // Thread id c-casted to uint64_t. + UnityProfilerThreadId threadId; + // Thread group name. NULL-terminated. + const char* groupName; + // Thread name. NULL-terminated. + const char* name; +} UnityProfilerThreadDesc; + +// Called when a new category is created. Up to 4 installed callbacks are supported. +// \param categoryDesc is a pointer to category description. +// \param userData is an optional context pointer passed with RegisterCreateCategoryCallback call. +typedef void (UNITY_INTERFACE_API * IUnityProfilerCreateCategoryCallback)(const UnityProfilerCategoryDesc* categoryDesc, void* userData); + +// Called when a new profiler marker is created. Up to 4 installed callbacks are supported. +// \param markerDesc is a pointer to marker description. +// \param userData is an optional context pointer passed with RegisterCreateEventCallback call. +typedef void (UNITY_INTERFACE_API * IUnityProfilerCreateMarkerCallback)(const UnityProfilerMarkerDesc* markerDesc, void* userData); + +// Called when a profiler event occurs. +// \param markerDesc is an marker description struct. +// \param eventType is an event type - UnityProfilerMarkerEventType_. +// \param eventDataCount is an event metadata count. +// \param eventData is a metadata array of eventDataCount elements. +// \param userData is an optional context pointer passed with RegisterCreateEventCallback call. +typedef void (UNITY_INTERFACE_API* IUnityProfilerMarkerEventCallback)(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData, void* userData); + +typedef void (UNITY_INTERFACE_API * IUnityProfilerBulkCounterDataEventCallback)(int counterGroup, size_t size, void* data, void* userData); + +// Called when a profiler frame change occurs. Up to 4 installed callbacks are supported. +// \param userData is an optional context pointer passed with RegisterCreateEventCallback call. +typedef void (UNITY_INTERFACE_API * IUnityProfilerFrameCallback)(void* userData); + +// Called when a profiler frame change occurs. Up to 4 installed callbacks are supported. +// \param userData is an optional context pointer passed with RegisterCreateEventCallback call. +typedef void (UNITY_INTERFACE_API * IUnityProfilerThreadCallback)(const UnityProfilerThreadDesc* threadDesc, void* userData); + +// Called when a profiler flow event occurs. +// Flow events connect events across threads allowing to trace related activities initiated from a control(main) thread. +// \param flowEventType is a flow event type. +// \param flowId is an unique incremental identifier for the flow chain. +// \param userData is an optional context pointer passed with RegisterCreateEventCallback call. +typedef void (UNITY_INTERFACE_API * IUnityProfilerFlowEventCallback)(UnityProfilerFlowEventType flowEventType, uint32_t flowId, void* userData); + +// Available since 2019.1 +UNITY_DECLARE_INTERFACE(IUnityProfilerCallbacksV2) +{ + // Register a callback which is called when a new category is created. + // Returns 0 on success and non-zero in case of error. + // Only up to 4 callbacks can be registered. + int(UNITY_INTERFACE_API * RegisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); + + // Register a callback which is called when a new marker is created. + // E.g. dynamically created in C# with "new PerformanceMarker(string)" or internally. + // Also is called for all existing markers when the callback is registered. + // Returns 0 on success and non-zero in case of error. + // Only up to 4 callbacks can be registered. + int(UNITY_INTERFACE_API * RegisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); + + // Register a callback which is called every time "PerformanceMarker.Begin(string)" is called or equivalent internal native counterpart. + // Returns 0 on success and non-zero in case of error. + // \param markerDesc is a pointer to marker description you want to install callback for. + int(UNITY_INTERFACE_API * RegisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); + // Unregister per-marker callback. + // \param markerDesc is a pointer to marker description you want to remove callback from. + // \param userData optional context pointer. + // If markerDesc is NULL, callback is removed from all events which have (callback, userData) pair. + // If both markerDesc and userData are NULL, callback is removed from all events which have callback function pointer. + int(UNITY_INTERFACE_API * UnregisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); + + // Register a callback which is called every time Profiler.BeginSample is called or equivalent internal native counterpart. + // Returns 0 on success and non-zero in case of error. + // Only up to 4 callbacks can be registered. + int(UNITY_INTERFACE_API * RegisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); + + // Register a callback which is called every time a new thread is registered with profiler. + // Returns 0 on success and non-zero in case of error. + // Only up to 4 callbacks can be registered. + int(UNITY_INTERFACE_API * RegisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); + + // Register a callback which is called every time Unity generates a flow event. + // Returns 0 on success and non-zero in case of error. + // Note: Flow events are supported only in Development Players and Editor. + int(UNITY_INTERFACE_API * RegisterFlowEventCallback)(IUnityProfilerFlowEventCallback callback, void* userData); + // Unregister flow event callback. + // \param userData optional context pointer. + int(UNITY_INTERFACE_API * UnregisterFlowEventCallback)(IUnityProfilerFlowEventCallback callback, void* userData); +}; +UNITY_REGISTER_INTERFACE_GUID(0x5DEB59E88F2D4571ULL, 0x81E8583069A5E33CULL, IUnityProfilerCallbacksV2) + +// Available since 2018.2 +UNITY_DECLARE_INTERFACE(IUnityProfilerCallbacks) +{ + int(UNITY_INTERFACE_API * RegisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); + + int(UNITY_INTERFACE_API * RegisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); + + int(UNITY_INTERFACE_API * RegisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); + + int(UNITY_INTERFACE_API * RegisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); + + int(UNITY_INTERFACE_API * RegisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); + int(UNITY_INTERFACE_API * UnregisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); +}; +UNITY_REGISTER_INTERFACE_GUID(0x572FDB38CE3C4B1FULL, 0xA6071A9A7C4F52D8ULL, IUnityProfilerCallbacks) diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityRenderingExtensions.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityRenderingExtensions.h new file mode 100644 index 0000000..fe3b515 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityRenderingExtensions.h @@ -0,0 +1,378 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once + + +#include "IUnityGraphics.h" + +/* + Low-level Native Plugin Rendering Extensions + ============================================ + + On top of the Low-level native plugin interface, Unity also supports low level rendering extensions that can receive callbacks when certain events happen. + This is mostly used to implement and control low-level rendering in your plugin and enable it to work with Unity’s multithreaded rendering. + + Due to the low-level nature of this extension the plugin might need to be preloaded before the devices get created. + Currently the convention is name-based namely the plugin name must be prefixed by “GfxPlugin”. Example: GfxPluginMyFancyNativePlugin. + + + // Native plugin code example + + enum PluginCustomCommands + { + kPluginCustomCommandDownscale = kUnityRenderingExtUserEventsStart, + kPluginCustomCommandUpscale, + + // insert your own events here + + kPluginCustomCommandCount + }; + + static IUnityInterfaces* s_UnityInterfaces = NULL; + + extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API + UnityPluginLoad(IUnityInterfaces* unityInterfaces) + { + // initialization code here... + } + + extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API + UnityRenderingExtEvent(UnityRenderingExtEventType event, void* data) + { + switch (event) + { + case kUnityRenderingExtEventBeforeDrawCall: + // do some stuff + break; + case kUnityRenderingExtEventAfterDrawCall: + // undo some stuff + break; + case kPluginCustomCommandDownscale: + // downscale some stuff + break; + case kPluginCustomCommandUpscale: + // upscale some stuff + break; + } + } + +*/ + + +// These events will be propagated to all plugins that implement void UnityRenderingExtEvent(UnityRenderingExtEventType event, void* data); + +typedef enum UnityRenderingExtEventType +{ + kUnityRenderingExtEventSetStereoTarget, // issued during SetStereoTarget and carrying the current 'eye' index as parameter + kUnityRenderingExtEventSetStereoEye, // issued during stereo rendering at the beginning of each eye's rendering loop. It carries the current 'eye' index as parameter + kUnityRenderingExtEventStereoRenderingDone, // issued after the rendering has finished + kUnityRenderingExtEventBeforeDrawCall, // issued during BeforeDrawCall and carrying UnityRenderingExtBeforeDrawCallParams as parameter + kUnityRenderingExtEventAfterDrawCall, // issued during AfterDrawCall. This event doesn't carry any parameters + kUnityRenderingExtEventCustomGrab, // issued during GrabIntoRenderTexture since we can't simply copy the resources + // when custom rendering is used - we need to let plugin handle this. It carries over + // a UnityRenderingExtCustomBlitParams params = { X, source, dest, 0, 0 } ( X means it's irrelevant ) + kUnityRenderingExtEventCustomBlit, // issued by plugin to insert custom blits. It carries over UnityRenderingExtCustomBlitParams as param. + kUnityRenderingExtEventUpdateTextureBegin, // Deprecated. + kUnityRenderingExtEventUpdateTextureEnd, // Deprecated. + kUnityRenderingExtEventUpdateTextureBeginV1 = kUnityRenderingExtEventUpdateTextureBegin, // Deprecated. Issued to update a texture. It carries over UnityRenderingExtTextureUpdateParamsV1 + kUnityRenderingExtEventUpdateTextureEndV1 = kUnityRenderingExtEventUpdateTextureEnd, // Deprecated. Issued to signal the plugin that the texture update has finished. It carries over the same UnityRenderingExtTextureUpdateParamsV1 as kUnityRenderingExtEventUpdateTextureBeginV1 + kUnityRenderingExtEventUpdateTextureBeginV2, // Issued to update a texture. It carries over UnityRenderingExtTextureUpdateParamsV2 + kUnityRenderingExtEventUpdateTextureEndV2, // Issued to signal the plugin that the texture update has finished. It carries over the same UnityRenderingExtTextureUpdateParamsV2 as kUnityRenderingExtEventUpdateTextureBeginV2 + + // keep this last + kUnityRenderingExtEventCount, + kUnityRenderingExtUserEventsStart = kUnityRenderingExtEventCount +} UnityRenderingExtEventType; + + +typedef enum UnityRenderingExtCustomBlitCommands +{ + kUnityRenderingExtCustomBlitVRFlush, // This event is mostly used in multi GPU configurations ( SLI, etc ) in order to allow the plugin to flush all GPU's targets + + // keep this last + kUnityRenderingExtCustomBlitCount, + kUnityRenderingExtUserCustomBlitStart = kUnityRenderingExtCustomBlitCount +} UnityRenderingExtCustomBlitCommands; + +/* + This will be propagated to all plugins implementing UnityRenderingExtQuery. +*/ +typedef enum UnityRenderingExtQueryType +{ + kUnityRenderingExtQueryOverrideViewport = 1 << 0, // The plugin handles setting up the viewport rects. Unity will skip its internal SetViewport calls + kUnityRenderingExtQueryOverrideScissor = 1 << 1, // The plugin handles setting up the scissor rects. Unity will skip its internal SetScissor calls + kUnityRenderingExtQueryOverrideVROcclussionMesh = 1 << 2, // The plugin handles its own VR occlusion mesh rendering. Unity will skip rendering its internal VR occlusion mask + kUnityRenderingExtQueryOverrideVRSinglePass = 1 << 3, // The plugin uses its own single pass stereo technique. Unity will only traverse and render the render node graph once. + // and it will clear the whole render target not just per-eye on demand. + kUnityRenderingExtQueryKeepOriginalDoubleWideWidth_DEPRECATED = 1 << 4, // Instructs unity to keep the original double wide width. By default unity will try and have a power-of-two width for mip-mapping requirements. + kUnityRenderingExtQueryRequestVRFlushCallback = 1 << 5, // Instructs unity to provide callbacks when the VR eye textures need flushing. Useful for multi GPU synchronization. + kUnityRenderingExtQueryOverridePresentFrame = 1 << 6, // The plugin handles it's own SwapChain Present. Unity will skip its internal Present calls +} UnityRenderingExtQueryType; + + +typedef enum UnityRenderingExtTextureFormat +{ + kUnityRenderingExtFormatNone = 0, kUnityRenderingExtFormatFirst = kUnityRenderingExtFormatNone, + + // sRGB formats + kUnityRenderingExtFormatR8_SRGB, + kUnityRenderingExtFormatR8G8_SRGB, + kUnityRenderingExtFormatR8G8B8_SRGB, + kUnityRenderingExtFormatR8G8B8A8_SRGB, + + // 8 bit integer formats + kUnityRenderingExtFormatR8_UNorm, + kUnityRenderingExtFormatR8G8_UNorm, + kUnityRenderingExtFormatR8G8B8_UNorm, + kUnityRenderingExtFormatR8G8B8A8_UNorm, + kUnityRenderingExtFormatR8_SNorm, + kUnityRenderingExtFormatR8G8_SNorm, + kUnityRenderingExtFormatR8G8B8_SNorm, + kUnityRenderingExtFormatR8G8B8A8_SNorm, + kUnityRenderingExtFormatR8_UInt, + kUnityRenderingExtFormatR8G8_UInt, + kUnityRenderingExtFormatR8G8B8_UInt, + kUnityRenderingExtFormatR8G8B8A8_UInt, + kUnityRenderingExtFormatR8_SInt, + kUnityRenderingExtFormatR8G8_SInt, + kUnityRenderingExtFormatR8G8B8_SInt, + kUnityRenderingExtFormatR8G8B8A8_SInt, + + // 16 bit integer formats + kUnityRenderingExtFormatR16_UNorm, + kUnityRenderingExtFormatR16G16_UNorm, + kUnityRenderingExtFormatR16G16B16_UNorm, + kUnityRenderingExtFormatR16G16B16A16_UNorm, + kUnityRenderingExtFormatR16_SNorm, + kUnityRenderingExtFormatR16G16_SNorm, + kUnityRenderingExtFormatR16G16B16_SNorm, + kUnityRenderingExtFormatR16G16B16A16_SNorm, + kUnityRenderingExtFormatR16_UInt, + kUnityRenderingExtFormatR16G16_UInt, + kUnityRenderingExtFormatR16G16B16_UInt, + kUnityRenderingExtFormatR16G16B16A16_UInt, + kUnityRenderingExtFormatR16_SInt, + kUnityRenderingExtFormatR16G16_SInt, + kUnityRenderingExtFormatR16G16B16_SInt, + kUnityRenderingExtFormatR16G16B16A16_SInt, + + // 32 bit integer formats + kUnityRenderingExtFormatR32_UInt, + kUnityRenderingExtFormatR32G32_UInt, + kUnityRenderingExtFormatR32G32B32_UInt, + kUnityRenderingExtFormatR32G32B32A32_UInt, + kUnityRenderingExtFormatR32_SInt, + kUnityRenderingExtFormatR32G32_SInt, + kUnityRenderingExtFormatR32G32B32_SInt, + kUnityRenderingExtFormatR32G32B32A32_SInt, + + // HDR formats + kUnityRenderingExtFormatR16_SFloat, + kUnityRenderingExtFormatR16G16_SFloat, + kUnityRenderingExtFormatR16G16B16_SFloat, + kUnityRenderingExtFormatR16G16B16A16_SFloat, + kUnityRenderingExtFormatR32_SFloat, + kUnityRenderingExtFormatR32G32_SFloat, + kUnityRenderingExtFormatR32G32B32_SFloat, + kUnityRenderingExtFormatR32G32B32A32_SFloat, + + // Luminance and Alpha format + kUnityRenderingExtFormatL8_UNorm, + kUnityRenderingExtFormatA8_UNorm, + kUnityRenderingExtFormatA16_UNorm, + + // BGR formats + kUnityRenderingExtFormatB8G8R8_SRGB, + kUnityRenderingExtFormatB8G8R8A8_SRGB, + kUnityRenderingExtFormatB8G8R8_UNorm, + kUnityRenderingExtFormatB8G8R8A8_UNorm, + kUnityRenderingExtFormatB8G8R8_SNorm, + kUnityRenderingExtFormatB8G8R8A8_SNorm, + kUnityRenderingExtFormatB8G8R8_UInt, + kUnityRenderingExtFormatB8G8R8A8_UInt, + kUnityRenderingExtFormatB8G8R8_SInt, + kUnityRenderingExtFormatB8G8R8A8_SInt, + + // 16 bit packed formats + kUnityRenderingExtFormatR4G4B4A4_UNormPack16, + kUnityRenderingExtFormatB4G4R4A4_UNormPack16, + kUnityRenderingExtFormatR5G6B5_UNormPack16, + kUnityRenderingExtFormatB5G6R5_UNormPack16, + kUnityRenderingExtFormatR5G5B5A1_UNormPack16, + kUnityRenderingExtFormatB5G5R5A1_UNormPack16, + kUnityRenderingExtFormatA1R5G5B5_UNormPack16, + + // Packed formats + kUnityRenderingExtFormatE5B9G9R9_UFloatPack32, + kUnityRenderingExtFormatB10G11R11_UFloatPack32, + + kUnityRenderingExtFormatA2B10G10R10_UNormPack32, + kUnityRenderingExtFormatA2B10G10R10_UIntPack32, + kUnityRenderingExtFormatA2B10G10R10_SIntPack32, + kUnityRenderingExtFormatA2R10G10B10_UNormPack32, + kUnityRenderingExtFormatA2R10G10B10_UIntPack32, + kUnityRenderingExtFormatA2R10G10B10_SIntPack32, + kUnityRenderingExtFormatA2R10G10B10_XRSRGBPack32, + kUnityRenderingExtFormatA2R10G10B10_XRUNormPack32, + kUnityRenderingExtFormatR10G10B10_XRSRGBPack32, + kUnityRenderingExtFormatR10G10B10_XRUNormPack32, + kUnityRenderingExtFormatA10R10G10B10_XRSRGBPack32, + kUnityRenderingExtFormatA10R10G10B10_XRUNormPack32, + + // ARGB formats... TextureFormat legacy + kUnityRenderingExtFormatA8R8G8B8_SRGB, + kUnityRenderingExtFormatA8R8G8B8_UNorm, + kUnityRenderingExtFormatA32R32G32B32_SFloat, + + // Depth Stencil for formats + kUnityRenderingExtFormatD16_UNorm, + kUnityRenderingExtFormatD24_UNorm, + kUnityRenderingExtFormatD24_UNorm_S8_UInt, + kUnityRenderingExtFormatD32_SFloat, + kUnityRenderingExtFormatD32_SFloat_S8_UInt, + kUnityRenderingExtFormatS8_UInt, + + // Compression formats + kUnityRenderingExtFormatRGBA_DXT1_SRGB, + kUnityRenderingExtFormatRGBA_DXT1_UNorm, + kUnityRenderingExtFormatRGBA_DXT3_SRGB, + kUnityRenderingExtFormatRGBA_DXT3_UNorm, + kUnityRenderingExtFormatRGBA_DXT5_SRGB, + kUnityRenderingExtFormatRGBA_DXT5_UNorm, + kUnityRenderingExtFormatR_BC4_UNorm, + kUnityRenderingExtFormatR_BC4_SNorm, + kUnityRenderingExtFormatRG_BC5_UNorm, + kUnityRenderingExtFormatRG_BC5_SNorm, + kUnityRenderingExtFormatRGB_BC6H_UFloat, + kUnityRenderingExtFormatRGB_BC6H_SFloat, + kUnityRenderingExtFormatRGBA_BC7_SRGB, + kUnityRenderingExtFormatRGBA_BC7_UNorm, + + kUnityRenderingExtFormatRGB_PVRTC_2Bpp_SRGB, + kUnityRenderingExtFormatRGB_PVRTC_2Bpp_UNorm, + kUnityRenderingExtFormatRGB_PVRTC_4Bpp_SRGB, + kUnityRenderingExtFormatRGB_PVRTC_4Bpp_UNorm, + kUnityRenderingExtFormatRGBA_PVRTC_2Bpp_SRGB, + kUnityRenderingExtFormatRGBA_PVRTC_2Bpp_UNorm, + kUnityRenderingExtFormatRGBA_PVRTC_4Bpp_SRGB, + kUnityRenderingExtFormatRGBA_PVRTC_4Bpp_UNorm, + + kUnityRenderingExtFormatRGB_ETC_UNorm, + kUnityRenderingExtFormatRGB_ETC2_SRGB, + kUnityRenderingExtFormatRGB_ETC2_UNorm, + kUnityRenderingExtFormatRGB_A1_ETC2_SRGB, + kUnityRenderingExtFormatRGB_A1_ETC2_UNorm, + kUnityRenderingExtFormatRGBA_ETC2_SRGB, + kUnityRenderingExtFormatRGBA_ETC2_UNorm, + + kUnityRenderingExtFormatR_EAC_UNorm, + kUnityRenderingExtFormatR_EAC_SNorm, + kUnityRenderingExtFormatRG_EAC_UNorm, + kUnityRenderingExtFormatRG_EAC_SNorm, + + kUnityRenderingExtFormatRGBA_ASTC4X4_SRGB, + kUnityRenderingExtFormatRGBA_ASTC4X4_UNorm, + kUnityRenderingExtFormatRGBA_ASTC5X5_SRGB, + kUnityRenderingExtFormatRGBA_ASTC5X5_UNorm, + kUnityRenderingExtFormatRGBA_ASTC6X6_SRGB, + kUnityRenderingExtFormatRGBA_ASTC6X6_UNorm, + kUnityRenderingExtFormatRGBA_ASTC8X8_SRGB, + kUnityRenderingExtFormatRGBA_ASTC8X8_UNorm, + kUnityRenderingExtFormatRGBA_ASTC10X10_SRGB, + kUnityRenderingExtFormatRGBA_ASTC10X10_UNorm, + kUnityRenderingExtFormatRGBA_ASTC12X12_SRGB, + kUnityRenderingExtFormatRGBA_ASTC12X12_UNorm, + + // Video formats + kUnityRenderingExtFormatYUV2, + + // Automatic formats, back-end decides + kUnityRenderingExtFormatDepthAuto_removed_donotuse, + kUnityRenderingExtFormatShadowAuto_removed_donotuse, + kUnityRenderingExtFormatVideoAuto_removed_donotuse, + + // ASTC hdr profile + kUnityRenderingExtFormatRGBA_ASTC4X4_UFloat, + kUnityRenderingExtFormatRGBA_ASTC5X5_UFloat, + kUnityRenderingExtFormatRGBA_ASTC6X6_UFloat, + kUnityRenderingExtFormatRGBA_ASTC8X8_UFloat, + kUnityRenderingExtFormatRGBA_ASTC10X10_UFloat, + kUnityRenderingExtFormatRGBA_ASTC12X12_UFloat, + + kUnityRenderingExtFormatLast = kUnityRenderingExtFormatRGBA_ASTC12X12_UFloat, // Remove? +} UnityRenderingExtTextureFormat; + + +typedef struct UnityRenderingExtBeforeDrawCallParams +{ + void* vertexShader; // bound vertex shader (platform dependent) + void* fragmentShader; // bound fragment shader (platform dependent) + void* geometryShader; // bound geometry shader (platform dependent) + void* hullShader; // bound hull shader (platform dependent) + void* domainShader; // bound domain shader (platform dependent) + int eyeIndex; // the index of the current stereo "eye" being currently rendered. +} UnityRenderingExtBeforeDrawCallParams; + + +typedef struct UnityRenderingExtCustomBlitParams +{ + UnityTextureID source; // source texture + UnityRenderBuffer destination; // destination surface + unsigned int command; // command for the custom blit - could be any UnityRenderingExtCustomBlitCommands command or custom ones. + unsigned int commandParam; // custom parameters for the command + unsigned int commandFlags; // custom flags for the command +} UnityRenderingExtCustomBlitParams; + +// Deprecated. Use UnityRenderingExtTextureUpdateParamsV2 and CommandBuffer.IssuePluginCustomTextureUpdateV2 instead. +// Only supports DX11, GLES, Metal +typedef struct UnityRenderingExtTextureUpdateParamsV1 +{ + void* texData; // source data for the texture update. Must be set by the plugin + unsigned int userData; // user defined data. Set by the plugin + + unsigned int textureID; // texture ID of the texture to be updated. + UnityRenderingExtTextureFormat format; // format of the texture to be updated + unsigned int width; // width of the texture + unsigned int height; // height of the texture + unsigned int bpp; // texture bytes per pixel. +} UnityRenderingExtTextureUpdateParamsV1; + +// Deprecated. Use UnityRenderingExtTextureUpdateParamsV2 and CommandBuffer.IssuePluginCustomTextureUpdateV2 instead. +// Only supports DX11, GLES, Metal +typedef UnityRenderingExtTextureUpdateParamsV1 UnityRenderingExtTextureUpdateParams; + +// Type of the "data" parameter passed when callbacks registered with CommandBuffer.IssuePluginCustomTextureUpdateV2 are called. +// Supports DX11, GLES, Metal, and Switch (also possibly PS4, PSVita in the future) +typedef struct UnityRenderingExtTextureUpdateParamsV2 +{ + void* texData; // source data for the texture update. Must be set by the plugin + intptr_t textureID; // texture ID of the texture to be updated. + unsigned int userData; // user defined data. Set by the plugin + UnityRenderingExtTextureFormat format; // format of the texture to be updated + unsigned int width; // width of the texture + unsigned int height; // height of the texture + unsigned int bpp; // texture bytes per pixel. +} UnityRenderingExtTextureUpdateParamsV2; + + +// Certain Unity APIs (GL.IssuePluginEventAndData, CommandBuffer.IssuePluginEventAndData) can callback into native plugins. +// Provide them with an address to a function of this signature. +typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data); + + +#ifdef __cplusplus +extern "C" { +#endif + +// If exported by a plugin, this function will be called for all the events in UnityRenderingExtEventType +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityRenderingExtEvent(UnityRenderingExtEventType event, void* data); +// If exported by a plugin, this function will be called to query the plugin for the queries in UnityRenderingExtQueryType +bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityRenderingExtQuery(UnityRenderingExtQueryType query); + +#ifdef __cplusplus +} +#endif diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityShaderCompilerAccess.h b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityShaderCompilerAccess.h new file mode 100644 index 0000000..220d393 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/IUnityShaderCompilerAccess.h @@ -0,0 +1,216 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once + + +#include "IUnityGraphics.h" + + +/* + Low-level Native Plugin Shader Compiler Access + ============================================== + + On top of the Low-level native plugin interface, Unity also supports low level access to the shader compiler, allowing the user to inject different variants into a shader. + It is also an event driven approach in which the plugin will receive callbacks when certain builtin events happen. +*/ + + +enum UnityShaderCompilerExtCompilerPlatform +{ + kUnityShaderCompilerExtCompPlatformUnused0 = 0, + kUnityShaderCompilerExtCompPlatformUnused1, + kUnityShaderCompilerExtCompPlatformUnused2, + kUnityShaderCompilerExtCompPlatformUnused3, + kUnityShaderCompilerExtCompPlatformD3D11, // Direct3D 11 (FL10.0 and up), compiled with MS D3DCompiler + kUnityShaderCompilerExtCompPlatformGLES20, // OpenGL ES 2.0 / WebGL 1.0, compiled with MS D3DCompiler + HLSLcc + kUnityShaderCompilerExtCompPlatformUnused6, + kUnityShaderCompilerExtCompPlatformUnused7, + kUnityShaderCompilerExtCompPlatformUnused8, + kUnityShaderCompilerExtCompPlatformGLES3Plus, // OpenGL ES 3.0+ / WebGL 2.0, compiled with MS D3DCompiler + HLSLcc + kUnityShaderCompilerExtCompPlatformUnused10, + kUnityShaderCompilerExtCompPlatformPS4, // Sony PS4 + kUnityShaderCompilerExtCompPlatformXboxOne, // MS XboxOne + kUnityShaderCompilerExtCompPlatformUnused13, + kUnityShaderCompilerExtCompPlatformMetal, // Apple Metal, compiled with MS D3DCompiler + HLSLcc + kUnityShaderCompilerExtCompPlatformOpenGLCore, // Desktop OpenGL 3+, compiled with MS D3DCompiler + HLSLcc + kUnityShaderCompilerExtCompPlatformUnused16, + kUnityShaderCompilerExtCompPlatformUnused17, + kUnityShaderCompilerExtCompPlatformVulkan, // Vulkan SPIR-V, compiled with MS D3DCompiler + HLSLcc + kUnityShaderCompilerExtCompPlatformSwitch, // Nintendo Switch (NVN) + kUnityShaderCompilerExtCompPlatformXboxOneD3D12, // Xbox One D3D12 + kUnityShaderCompilerExtCompPlatformGameCoreXboxOne, // GameCore XboxOne + kUnityShaderCompilerExtCompPlatformGameCoreXboxSeries,// GameCore XboxSeries + kUnityShaderCompilerExtCompPlatformPS5, + kUnityShaderCompilerExtCompPlatformPS5NGGC, + kUnityShaderCompilerExtCompPlatformUnused25, + kUnityShaderCompilerExtCompPlatformCount +}; + + +enum UnityShaderCompilerExtShaderType +{ + kUnityShaderCompilerExtShaderNone = 0, + kUnityShaderCompilerExtShaderVertex = 1, + kUnityShaderCompilerExtShaderFragment = 2, + kUnityShaderCompilerExtShaderGeometry = 3, + kUnityShaderCompilerExtShaderHull = 4, + kUnityShaderCompilerExtShaderDomain = 5, + kUnityShaderCompilerExtShaderRayTracing = 6, + kUnityShaderCompilerExtShaderTypeCount // keep this last! +}; + + +enum UnityShaderCompilerExtGPUProgramType +{ + kUnityShaderCompilerExtGPUProgramTargetUnknown = 0, + + kUnityShaderCompilerExtGPUProgramTargetGLLegacy = 1, // removed + kUnityShaderCompilerExtGPUProgramTargetGLES31AEP = 2, + kUnityShaderCompilerExtGPUProgramTargetGLES31 = 3, + kUnityShaderCompilerExtGPUProgramTargetGLES3 = 4, + kUnityShaderCompilerExtGPUProgramTargetGLES = 5, + kUnityShaderCompilerExtGPUProgramTargetGLCore32 = 6, + kUnityShaderCompilerExtGPUProgramTargetGLCore41 = 7, + kUnityShaderCompilerExtGPUProgramTargetGLCore43 = 8, + kUnityShaderCompilerExtGPUProgramTargetDX9VertexSM20 = 9, // removed + kUnityShaderCompilerExtGPUProgramTargetDX9VertexSM30 = 10, // removed + kUnityShaderCompilerExtGPUProgramTargetDX9PixelSM20 = 11, // removed + kUnityShaderCompilerExtGPUProgramTargetDX9PixelSM30 = 12, // removed + kUnityShaderCompilerExtGPUProgramTargetDX10Level9Vertex = 13, + kUnityShaderCompilerExtGPUProgramTargetDX10Level9Pixel = 14, + kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM40 = 15, + kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM50 = 16, + kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM40 = 17, + kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM50 = 18, + kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM40 = 19, + kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM50 = 20, + kUnityShaderCompilerExtGPUProgramTargetDX11HullSM50 = 21, + kUnityShaderCompilerExtGPUProgramTargetDX11DomainSM50 = 22, + kUnityShaderCompilerExtGPUProgramTargetMetalVS = 23, + kUnityShaderCompilerExtGPUProgramTargetMetalFS = 24, + kUnityShaderCompilerExtGPUProgramTargetSPIRV = 25, + kUnityShaderCompilerExtGPUProgramTargetUnused1 = 26, + kUnityShaderCompilerExtGPUProgramTargetUnused2 = 27, + kUnityShaderCompilerExtGPUProgramTargetUnused3 = 28, + kUnityShaderCompilerExtGPUProgramTargetUnused4 = 29, + kUnityShaderCompilerExtGPUProgramTargetUnused5 = 30, + kUnityShaderCompilerExtGPUProgramTargetRayTracing = 31, + kUnityShaderCompilerExtGPUProgramTargetPS5NGGC = 32, + + kUnityShaderCompilerExtGPUProgramTargetCount +}; + + +enum UnityShaderCompilerExtGPUProgram +{ + kUnityShaderCompilerExtGPUProgramVS = 1 << kUnityShaderCompilerExtShaderVertex, + kUnityShaderCompilerExtGPUProgramPS = 1 << kUnityShaderCompilerExtShaderFragment, + kUnityShaderCompilerExtGPUProgramGS = 1 << kUnityShaderCompilerExtShaderGeometry, + kUnityShaderCompilerExtGPUProgramHS = 1 << kUnityShaderCompilerExtShaderHull, + kUnityShaderCompilerExtGPUProgramDS = 1 << kUnityShaderCompilerExtShaderDomain, + kUnityShaderCompilerExtGPUProgramCustom = 1 << kUnityShaderCompilerExtShaderTypeCount +}; + + +enum UnityShaderCompilerExtEventType +{ + kUnityShaderCompilerExtEventCreateCustomSourceVariant, // The plugin can create a new variant based on the initial snippet. The callback will receive UnityShaderCompilerExtCustomSourceVariantParams as data. + kUnityShaderCompilerExtEventCreateCustomSourceVariantCleanup, // Typically received after the kUnityShaderCompilerExtEventCreateCustomVariant event so the plugin has a chance to cleanup after itself. (outputSnippet & outputKeyword) + + kUnityShaderCompilerExtEventCreateCustomBinaryVariant, // The plugin can create a new variant based on the initial snippet. The callback will receive UnityShaderCompilerExtCustomBinaryVariantParams as data. + kUnityShaderCompilerExtEventCreateCustomBinaryVariantCleanup, // Typically received after the kUnityShaderCompilerExtEventCreateCustomVariant event so the plugin has a chance to cleanup after itself. (outputSnippet & outputKeyword) + kUnityShaderCompilerExtEventPluginConfigure, // Event sent so the plugin can configure itself. It receives IUnityShaderCompilerExtPluginConfigure* as data + + // keep these last + kUnityShaderCompilerExtEventCount, + kUnityShaderCompilerExtUserEventsStart = kUnityShaderCompilerExtEventCount +}; + + +struct UnityShaderCompilerExtCustomSourceVariantParams +{ + char* outputSnippet; // snippet after the plugin has finished processing it. + char* outputKeywords; // keywords exported by the plugin for this specific variant + const char* inputSnippet; // the source shader snippet + bool vr; // is VR enabled / supported ? + UnityShaderCompilerExtCompilerPlatform platform; // compiler platform + UnityShaderCompilerExtShaderType shaderType; // source code type +}; + + +struct UnityShaderCompilerExtCustomBinaryVariantParams +{ + void** outputBinaryShader; // output of the plugin generated binary shader (platform dependent) + const unsigned char* inputByteCode; // the shader byteCode (platform dependent) + unsigned int inputByteCodeSize; // shader bytecode size + unsigned int programTypeMask; // a mask of UnityShaderCompilerExtGPUProgram values + UnityShaderCompilerExtCompilerPlatform platform; // compiler platform +}; + + +/* + This class is queried by unity to get information about the plugin. + The plugin has to set all the relevant values during the kUnityShaderCompilerExtEventPluginConfigure event. + + + + extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API + UnityShaderCompilerExtEvent(UnityShaderCompilerExtEventType event, void* data) + { + switch (event) + { + + ... + + case kUnityShaderCompilerExtEventPluginConfigure: + { + unsigned int GPUCompilerMask = (1 << kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM40) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM50) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM40) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM50) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM40) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM50) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11HullSM50) + | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11DomainSM50); + + unsigned int ShaderMask = kUnityShaderCompilerExtGPUProgramVS | kUnityShaderCompilerExtGPUProgramDS; + + IUnityShaderCompilerExtPluginConfigure* pluginConfig = (IUnityShaderCompilerExtPluginConfigure*)data; + pluginConfig->ReserveKeyword(SHADER_KEYWORDS); + pluginConfig->SetGPUProgramCompilerMask(GPUCompilerMask); + pluginConfig->SetShaderProgramMask(ShaderMask); + break; + } + } + } + + +*/ + +class IUnityShaderCompilerExtPluginConfigure +{ +public: + virtual ~IUnityShaderCompilerExtPluginConfigure() {} + virtual void ReserveKeyword(const char* keyword) = 0; // Allow the plugin to reserve its keyword so unity can include it in calculating the variants + virtual void SetGPUProgramCompilerMask(unsigned int mask) = 0; // Specifies a bit mask of UnityShaderCompilerExtGPUProgramType programs the plugin supports compiling + virtual void SetShaderProgramMask(unsigned int mask) = 0; // Specifies a bit mask of UnityShaderCompilerExtGPUProgram programs the plugin supports compiling +}; + + +// Interface to help setup / configure both unity and the plugin. + + +#ifdef __cplusplus +extern "C" { +#endif + +// If exported by a plugin, this function will be called for all the events in UnityShaderCompilerExtEventType +void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityShaderCompilerExtEvent(UnityShaderCompilerExtEventType event, void* data); + +#ifdef __cplusplus +} +#endif diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/LICENSE.md b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/LICENSE.md new file mode 100644 index 0000000..7b839ca --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/include/LICENSE.md @@ -0,0 +1,5 @@ +Unity Native Plugin API copyright © 2015 Unity Technologies ApS + +Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). + +Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/src/lib.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/src/lib.rs new file mode 100644 index 0000000..862ee7b --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/src/lib.rs @@ -0,0 +1,23 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(unsafe_op_in_unsafe_fn)] + +#[cfg(target_os = "linux")] +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +#[cfg(target_os = "linux")] +pub mod egl { + include!(concat!(env!("OUT_DIR"), "/bindings_egl.rs")); +} + +#[cfg(target_os = "linux")] +pub mod gl { + include!(concat!(env!("OUT_DIR"), "/bindings_gl.rs")); +} + +#[cfg(target_os = "linux")] +pub mod gtk { + include!(concat!(env!("OUT_DIR"), "/bindings_gtk3.rs")); + include!(concat!(env!("OUT_DIR"), "/bindings_gio.rs")); +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_egl.hpp b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_egl.hpp new file mode 100644 index 0000000..13eef0d --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_egl.hpp @@ -0,0 +1 @@ +#include diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_gl.hpp b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_gl.hpp new file mode 100644 index 0000000..0dc404c --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_gl.hpp @@ -0,0 +1,2 @@ +#include +#include diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_linux.hpp b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_linux.hpp new file mode 100644 index 0000000..fa8bad5 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb-native/wrapper_linux.hpp @@ -0,0 +1,7 @@ +#include +#include +#include +#include + +#include "IUnityGraphics.h" +#include "IUnityGraphicsVulkan.h" diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/Cargo.toml b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/Cargo.toml new file mode 100644 index 0000000..15bd558 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "ufb" +version = "0.1.0" +edition = "2024" + +[lib] +name = "ufb" +crate-type = ["rlib", "cdylib"] + +[dependencies] +opener = { version = "0.8.2", features = ["reveal"] } +raw-window-handle = "0.6.2" +rfd = "0.15.3" +ufb-native = { path = "../ufb-native" } + +[target.'cfg(target_os = "windows")'.dependencies.windows] +version = "0.61.1" +features = ["Win32_UI_WindowsAndMessaging"] + +[target.'cfg(target_os = "macos")'.dependencies] +objc2 = "0.6.1" +objc2-app-kit = "0.3.1" +# objc2-foundation = "0.3.1" +dispatch2 = "0.3.0" diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/linux.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/linux.rs new file mode 100644 index 0000000..888b374 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/linux.rs @@ -0,0 +1,195 @@ +use std::{ + ffi::CStr, + ptr::{NonNull, null_mut}, +}; + +use ufb_native::{ + IUnityGraphics, IUnityGraphicsVulkan, IUnityGraphicsVulkanV2, IUnityInterfaces, + PFN_vkCreateWaylandSurfaceKHR, PFN_vkCreateXlibSurfaceKHR, PFN_vkGetInstanceProcAddr, + PFN_vkVoidFunction, UnityGfxDeviceEventType, + UnityGfxDeviceEventType_kUnityGfxDeviceEventInitialize, + UnityGfxRenderer_kUnityGfxRendererOpenGLCore, VkAllocationCallbacks, VkInstance, VkResult, + VkSurfaceKHR, VkWaylandSurfaceCreateInfoKHR, VkXlibSurfaceCreateInfoKHR, egl::EGL, gl::GL, +}; + +use crate::utils::linux::{LinuxWindowRef, set_window_handle}; + +static mut UNITY_INTERFACES: *mut IUnityInterfaces = null_mut(); +static mut UNITY_GRAPHICS: *mut IUnityGraphics = null_mut(); + +static mut UNITY_GRAPHICS_VK: *mut IUnityGraphicsVulkan = null_mut(); +static mut UNITY_GRAPHICS_VK2: *mut IUnityGraphicsVulkanV2 = null_mut(); + +fn get_interfaces<'a>() -> &'a IUnityInterfaces { + unsafe { + let interfaces = &*UNITY_INTERFACES; + + interfaces + } +} + +fn get_graphics<'a>() -> &'a IUnityGraphics { + unsafe { + let interfaces = &*UNITY_GRAPHICS; + + interfaces + } +} + +#[allow(non_snake_case)] +#[unsafe(no_mangle)] +pub extern "C" fn UnityPluginLoad(interfaces: *mut IUnityInterfaces) { + unsafe { + UNITY_INTERFACES = interfaces; + let interfaces = get_interfaces(); + UNITY_GRAPHICS = + (interfaces.GetInterfaceSplit.unwrap()(0x7CBA0A9CA4DDB544, 0x8C5AD4926EB17B11)) + as *mut IUnityGraphics; + + let graphics = get_graphics(); + graphics.RegisterDeviceEventCallback.unwrap()(Some(on_graphics_device_event)); + on_graphics_device_event(UnityGfxDeviceEventType_kUnityGfxDeviceEventInitialize); + } +} + +#[allow(unsafe_op_in_unsafe_fn)] +unsafe extern "C" fn on_graphics_device_event(event_type: UnityGfxDeviceEventType) { + if event_type == UnityGfxDeviceEventType_kUnityGfxDeviceEventInitialize { + init_vulkan(); + + let g = get_graphics(); + + #[allow(non_upper_case_globals)] + match g.GetRenderer.unwrap()() { + UnityGfxRenderer_kUnityGfxRendererOpenGLCore => { + init_opengl(); + } + _ => {} + } + } +} + +unsafe fn init_opengl() { + unsafe { + match GL::new("libGL.so.1") { + Ok(gl) => { + let display = gl.glXGetCurrentDisplay(); + if let Some(display) = NonNull::new(display as _) { + set_window_handle(LinuxWindowRef::Xlib { + window: gl.glXGetCurrentDrawable(), + display, + }); + + return; + } + } + Err(e) => eprintln!("failed to load libGL: {e:?}"), + } + match EGL::new("libEGL.so.1") { + Ok(egl) => { + dbg!(egl.eglGetCurrentDisplay()); + } + Err(e) => eprintln!("failed to load libEGL: {e:?}"), + } + } +} + +unsafe fn init_vulkan() { + unsafe { + UNITY_GRAPHICS_VK = + get_interfaces().GetInterfaceSplit.unwrap()(0x95355348d4ef4e11, 0x9789313dfcffcc87) + as *mut IUnityGraphicsVulkan; + UNITY_GRAPHICS_VK2 = + get_interfaces().GetInterfaceSplit.unwrap()(0x329334C09DCA4787, 0xB347DD92A0097FFC) + as *mut IUnityGraphicsVulkanV2; + + if UNITY_GRAPHICS_VK.is_null() || UNITY_GRAPHICS_VK2.is_null() { + return; + } + + let vk = &*UNITY_GRAPHICS_VK; + + vk.InterceptInitialization.unwrap()(Some(unity_vk_init), null_mut()); + } +} + +static mut ORIG_GET_INSTANCE_PROC_ADDR: PFN_vkGetInstanceProcAddr = None; +static mut ORIG_CREATE_WAYLAND_SURFACE_KHR: PFN_vkCreateWaylandSurfaceKHR = None; +static mut ORIG_CREATE_XLIB_SURFACE_KHR: PFN_vkCreateXlibSurfaceKHR = None; + +unsafe extern "C" fn unity_vk_init( + orig_get_instance_proc_addr: PFN_vkGetInstanceProcAddr, + _userdata: *mut ::std::os::raw::c_void, +) -> PFN_vkGetInstanceProcAddr { + unsafe { ORIG_GET_INSTANCE_PROC_ADDR = orig_get_instance_proc_addr }; + Some(get_instance_proc_addr) +} + +unsafe extern "C" fn get_instance_proc_addr( + instance: VkInstance, + p_name: *const ::std::os::raw::c_char, +) -> PFN_vkVoidFunction { + unsafe { + let str = CStr::from_ptr(p_name).to_str().unwrap(); + if str == "vkCreateWaylandSurfaceKHR" { + if let Some(orig) = ORIG_GET_INSTANCE_PROC_ADDR { + let orig_fn: PFN_vkCreateWaylandSurfaceKHR = + orig(instance, p_name).map(|x| std::mem::transmute(x)); + ORIG_CREATE_WAYLAND_SURFACE_KHR = orig_fn; + println!("[UnityFileBrowser] intercepting {str}"); + return Some(std::mem::transmute( + vk_create_wayland_surface_khr_hook as *const (), + )); + } + } + if str == "vkCreateXlibSurfaceKHR" { + if let Some(orig) = ORIG_GET_INSTANCE_PROC_ADDR { + let orig_fn: PFN_vkCreateXlibSurfaceKHR = + orig(instance, p_name).map(|x| std::mem::transmute(x)); + ORIG_CREATE_XLIB_SURFACE_KHR = orig_fn; + println!("[UnityFileBrowser] intercepting {str}"); + return Some(std::mem::transmute(vk_create_xlib_surface_khr as *const ())); + } + } + + ORIG_GET_INSTANCE_PROC_ADDR + .map(move |x| x(instance, p_name)) + .flatten() + } +} + +unsafe extern "C" fn vk_create_wayland_surface_khr_hook( + instance: VkInstance, + create_info: *const VkWaylandSurfaceCreateInfoKHR, + allocator: *const VkAllocationCallbacks, + surface: *mut VkSurfaceKHR, +) -> VkResult { + unsafe { + dbg!((&*create_info).display); + let orig_fn = + ORIG_CREATE_WAYLAND_SURFACE_KHR.expect("vkCreateWaylandSurfaceKHR orig fn not found"); + + orig_fn(instance, create_info, allocator, surface) + } +} + +unsafe extern "C" fn vk_create_xlib_surface_khr( + instance: VkInstance, + create_info: *const VkXlibSurfaceCreateInfoKHR, + allocator: *const VkAllocationCallbacks, + surface: *mut VkSurfaceKHR, +) -> VkResult { + unsafe { + let info = &*create_info; + + set_window_handle(LinuxWindowRef::Xlib { + display: NonNull::new(info.dpy as _).expect("x display is null"), + window: info.window as _, + }); + + let orig_fn = + ORIG_CREATE_XLIB_SURFACE_KHR.expect("vkCreateWaylandSurfaceKHR orig fn not found"); + + orig_fn(instance, create_info, allocator, surface) + } +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/lib.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/mod.rs similarity index 56% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/lib.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/mod.rs index 6ce30e4..d537ac3 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/src/lib.rs +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/entrypoint/mod.rs @@ -1,11 +1,10 @@ -mod filedialog; -mod opener; -mod utils; - use std::ffi::{CString, c_char}; -pub use filedialog::*; -pub use opener::*; +#[cfg(target_os = "linux")] +mod linux; + +#[cfg(target_os = "linux")] +pub use linux::*; /// # Safety /// @@ -18,13 +17,3 @@ pub unsafe extern "C" fn cstring_free(ptr: *mut c_char) { } } } - -#[test] -fn test_file_dialog() { - FileDialog::new().pick_file(); -} - -#[test] -fn test_file_opener() { - reveal("Cargo.toml"); -} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/filedialog/buffer.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/filedialog/buffer.rs similarity index 100% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/filedialog/buffer.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/filedialog/buffer.rs diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/filedialog/mod.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/filedialog/mod.rs similarity index 96% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/filedialog/mod.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/filedialog/mod.rs index 8c18e84..ee2a989 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/src/filedialog/mod.rs +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/filedialog/mod.rs @@ -20,7 +20,16 @@ impl Default for FileDialog { impl FileDialog { #[cfg(target_os = "linux")] pub fn new() -> Self { - Self::_new() + let mut dialog = Self::_new(); + + let window = crate::utils::linux::get_window_handle(); + if let Some(window) = &window { + dialog.dialog = dialog.dialog.set_parent(window); + }; + + dbg!(&dialog.dialog); + + dialog } #[cfg(target_os = "macos")] diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/lib.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/lib.rs new file mode 100644 index 0000000..2418421 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/lib.rs @@ -0,0 +1,20 @@ +mod filedialog; +mod opener; +mod utils; + +pub use filedialog::*; +pub use opener::*; + +mod entrypoint; + +pub use entrypoint::*; + +#[test] +fn test_file_dialog() { + FileDialog::new().pick_file(); +} + +#[test] +fn test_file_opener() { + reveal("Cargo.toml"); +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/opener.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/opener.rs similarity index 100% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/opener.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/opener.rs diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/linux.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/linux.rs new file mode 100644 index 0000000..86e1c76 --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/linux.rs @@ -0,0 +1,56 @@ +use std::{ + ffi::{c_ulong, c_void}, + ptr::NonNull, + sync::Mutex, +}; + +use raw_window_handle::{ + DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, WindowHandle, XlibDisplayHandle, + XlibWindowHandle, +}; + +#[derive(Clone)] +pub enum LinuxWindowRef { + Xlib { + display: NonNull, + window: c_ulong, + }, +} + +static CURRENT_WINDOW: Mutex> = Mutex::new(None); + +unsafe impl Send for LinuxWindowRef {} +unsafe impl Sync for LinuxWindowRef {} + +pub fn set_window_handle(handle: LinuxWindowRef) { + let mut data = CURRENT_WINDOW.lock().unwrap(); + *data = Some(handle); +} + +pub fn get_window_handle() -> Option { + let value = CURRENT_WINDOW.lock().unwrap(); + value.clone() +} + +impl HasWindowHandle for LinuxWindowRef { + fn window_handle(&self) -> Result, HandleError> { + unsafe { + match self { + Self::Xlib { window, .. } => Ok(WindowHandle::borrow_raw( + XlibWindowHandle::new(*window).into(), + )), + } + } + } +} +impl HasDisplayHandle for LinuxWindowRef { + fn display_handle(&self) -> Result, HandleError> { + unsafe { + match self { + Self::Xlib { display, .. } => Ok(DisplayHandle::borrow_raw( + XlibDisplayHandle::new(Some(*display), 0).into(), + )), + } + } + } +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/macos.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/macos.rs similarity index 100% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/macos.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/macos.rs diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/mod.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/mod.rs similarity index 67% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/mod.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/mod.rs index cdc0dc5..6ed2521 100644 --- a/Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/mod.rs +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/mod.rs @@ -3,3 +3,6 @@ pub mod macos; #[cfg(target_os = "windows")] pub mod windows; + +#[cfg(target_os = "linux")] +pub mod linux; diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/windows.rs b/Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/windows.rs similarity index 100% rename from Packages/com.7thbeat.filebrowser/PluginSource~/src/utils/windows.rs rename to Packages/com.7thbeat.filebrowser/PluginSource~/crates/ufb/src/utils/windows.rs diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.lock b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.lock new file mode 100644 index 0000000..a28d79d --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.lock @@ -0,0 +1,103 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1749416335, + "owner": "cachix", + "repo": "devenv", + "rev": "e8fffc7d61259f27c27b0fbe39a052a604807a2e", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1747046372, + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747372754, + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1746807397, + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": [ + "git-hooks" + ] + } + } + }, + "root": "root", + "version": 7 +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.nix b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.nix new file mode 100644 index 0000000..0093a6e --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.nix @@ -0,0 +1,13 @@ +{ pkgs, lib, ... }: + +{ + # https://devenv.sh/basics/ + env.LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + # env.BINDGEN_EXTRA_CLANG_ARGS = "-I\"${pkgs.vulkan-headers}/include\" -I\"${pkgs.xorg.libX11}/include\" -I\"${pkgs.libGL.dev}/include\" -I\"${pkgs.gtk3.dev}/include/gtk-3.0\" -I\"${pkgs.glib.dev}/include/glib-2.0\""; + + # https://devenv.sh/packages/ + packages = with pkgs; [ git pkg-config llvmPackages.clang glibc.dev rust-bindgen xorg.libX11 glib.dev libGL.dev gtk3.dev vulkan-headers ]; + + # https://devenv.sh/languages/ + languages.rust.enable = true; +} diff --git a/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.yaml b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.yaml new file mode 100644 index 0000000..116a2ad --- /dev/null +++ b/Packages/com.7thbeat.filebrowser/PluginSource~/devenv.yaml @@ -0,0 +1,15 @@ +# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json +inputs: + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling + +# If you're using non-OSS software, you can set allowUnfree to true. +# allowUnfree: true + +# If you're willing to use a package that's vulnerable +# permittedInsecurePackages: +# - "openssl-1.1.1w" + +# If you have more than one devenv you can merge them +#imports: +# - ./backend diff --git a/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so b/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so old mode 100644 new mode 100755 index e6c4675..24317ed Binary files a/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so and b/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so differ diff --git a/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so.meta b/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so.meta index 7cf8046..b9bf9f0 100644 --- a/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so.meta +++ b/Packages/com.7thbeat.filebrowser/Plugins/x86_64/libufb.so.meta @@ -6,7 +6,7 @@ PluginImporter: iconMap: {} executionOrder: {} defineConstraints: [] - isPreloaded: 0 + isPreloaded: 1 isOverridable: 1 isExplicitlyReferenced: 0 validateReferences: 1 diff --git a/ProjectSettings/BurstAotSettings_Android.json b/ProjectSettings/BurstAotSettings_Android.json new file mode 100644 index 0000000..ce2d8aa --- /dev/null +++ b/ProjectSettings/BurstAotSettings_Android.json @@ -0,0 +1,17 @@ +{ + "MonoBehaviour": { + "Version": 4, + "EnableBurstCompilation": true, + "EnableOptimisations": true, + "EnableSafetyChecks": false, + "EnableDebugInAllBuilds": false, + "DebugDataKind": 1, + "EnableArmv9SecurityFeatures": false, + "CpuMinTargetX32": 0, + "CpuMaxTargetX32": 0, + "CpuMinTargetX64": 0, + "CpuMaxTargetX64": 0, + "CpuTargetsArm64": 512, + "OptimizeFor": 0 + } +} diff --git a/ProjectSettings/BurstAotSettings_iOS.json b/ProjectSettings/BurstAotSettings_iOS.json new file mode 100644 index 0000000..eed54c3 --- /dev/null +++ b/ProjectSettings/BurstAotSettings_iOS.json @@ -0,0 +1,16 @@ +{ + "MonoBehaviour": { + "Version": 4, + "EnableBurstCompilation": true, + "EnableOptimisations": true, + "EnableSafetyChecks": false, + "EnableDebugInAllBuilds": false, + "DebugDataKind": 1, + "EnableArmv9SecurityFeatures": false, + "CpuMinTargetX32": 0, + "CpuMaxTargetX32": 0, + "CpuMinTargetX64": 0, + "CpuMaxTargetX64": 0, + "OptimizeFor": 0 + } +} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index d7b397c..2c55ab4 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -12,7 +12,7 @@ PlayerSettings: targetDevice: 2 useOnDemandResources: 0 accelerometerFrequency: 60 - companyName: DefaultCompany + companyName: 7th Beat Games productName: UnityFileDialog defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} @@ -511,6 +511,9 @@ PlayerSettings: - m_BuildTarget: iOSSupport m_APIs: 10000000 m_Automatic: 1 + - m_BuildTarget: LinuxStandaloneSupport + m_APIs: 1100000015000000 + m_Automatic: 0 m_BuildTargetVRSettings: [] m_DefaultShaderChunkSizeInMB: 16 m_DefaultShaderChunkCount: 0