From c0b54be6922648bc0d68f10a8640ff427c6d1d58 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 16 Dec 2025 00:53:03 +0200 Subject: [PATCH 1/5] Fix clang bindings code generation for non-const ref parameters --- .../Flax.Build/Bindings/BindingsGenerator.Cpp.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 190036af4..8554152fb 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -1293,11 +1293,21 @@ namespace Flax.Build.Bindings callParams += parameterInfo.Name; callParams += "Temp"; } - // Instruct for more optoimized value move operation + // Instruct for more optimized value move operation else if (parameterInfo.Type.IsMoveRef) { callParams += $"MoveTemp({param})"; } + else if (parameterInfo.Type.IsRef && !parameterInfo.Type.IsConst) + { + // Non-const lvalue reference parameters needs to be passed via temporary value + if (parameterInfo.IsOut || parameterInfo.IsRef) + contents.Append(indent).AppendFormat("{2}& {0}Temp = {1};", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine(); + else + contents.Append(indent).AppendFormat("{2} {0}Temp = {1};", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine(); + callParams += parameterInfo.Name; + callParams += "Temp"; + } else { callParams += param; From 518a19c857c3333a51af14493995f93bd2b1229b Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 16 Dec 2025 14:27:32 +0200 Subject: [PATCH 2/5] Expose `RenderContext` to scripting API --- Source/Engine/Graphics/RenderTask.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h index 07926fd64..8cba1006e 100644 --- a/Source/Engine/Graphics/RenderTask.h +++ b/Source/Engine/Graphics/RenderTask.h @@ -450,7 +450,7 @@ public: /// /// The high-level renderer context. Used to collect the draw calls for the scene rendering. Can be used to perform a custom rendering. /// -API_STRUCT(NoDefault) struct RenderContext +API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContext { DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContext); @@ -491,7 +491,7 @@ API_STRUCT(NoDefault) struct RenderContext /// /// The high-level renderer context batch that encapsulates multiple rendering requests within a single task (eg. optimize main view scene rendering and shadow projections at once). /// -API_STRUCT(NoDefault) struct RenderContextBatch +API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContextBatch { DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContextBatch); From f95cbb0e52e1802ff8193bc637f4531a3913b588 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 16 Dec 2025 14:29:42 +0200 Subject: [PATCH 3/5] Fix missing exports for managed converter structures --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 8554152fb..33f9d3514 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -3005,7 +3005,7 @@ namespace Flax.Build.Bindings // Generate MConverter for a structure header.Append("template<>").AppendLine(); - header.AppendFormat("struct MConverter<{0}>", fullName).AppendLine(); + header.AppendFormat("struct DLLEXPORT MConverter<{0}>", fullName).AppendLine(); header.Append('{').AppendLine(); header.AppendFormat(" MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); header.Append(" {").AppendLine(); @@ -3115,7 +3115,7 @@ namespace Flax.Build.Bindings { // Generate MConverter for a class header.Append("template<>").AppendLine(); - header.AppendFormat("struct MConverter<{0}>", fullName).AppendLine(); + header.AppendFormat("struct DLLEXPORT MConverter<{0}>", fullName).AppendLine(); header.Append('{').AppendLine(); header.AppendFormat(" static MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); From 52e2327527bde83806f2de052b16e45aae6cc877 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 16 Dec 2025 21:11:36 +0200 Subject: [PATCH 4/5] Add `USED` attribute for forcing compiler to emit the symbol --- Source/Engine/Core/Compiler.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Core/Compiler.h b/Source/Engine/Core/Compiler.h index a45a4628a..d84713857 100644 --- a/Source/Engine/Core/Compiler.h +++ b/Source/Engine/Core/Compiler.h @@ -4,8 +4,9 @@ #if defined(__clang__) -#define DLLEXPORT __attribute__ ((__visibility__ ("default"))) +#define DLLEXPORT __attribute__((__visibility__("default"))) #define DLLIMPORT +#define USED __attribute__((used)) #define THREADLOCAL __thread #define STDCALL __attribute__((stdcall)) #define CDECL __attribute__((cdecl)) @@ -19,7 +20,7 @@ #define PACK_BEGIN() #define PACK_END() __attribute__((__packed__)) #define ALIGN_BEGIN(_align) -#define ALIGN_END(_align) __attribute__( (aligned(_align) ) ) +#define ALIGN_END(_align) __attribute__((aligned(_align))) #define OFFSET_OF(X, Y) __builtin_offsetof(X, Y) #define PRAGMA_DISABLE_DEPRECATION_WARNINGS \ _Pragma("clang diagnostic push") \ @@ -37,8 +38,9 @@ #elif defined(__GNUC__) -#define DLLEXPORT __attribute__ ((__visibility__ ("default"))) +#define DLLEXPORT __attribute__((__visibility__("default"))) #define DLLIMPORT +#define USED __attribute__((used)) #define THREADLOCAL __thread #define STDCALL __attribute__((stdcall)) #define CDECL __attribute__((cdecl)) @@ -52,7 +54,7 @@ #define PACK_BEGIN() #define PACK_END() __attribute__((__packed__)) #define ALIGN_BEGIN(_align) -#define ALIGN_END(_align) __attribute__( (aligned(_align) ) ) +#define ALIGN_END(_align) __attribute__((aligned(_align))) #define OFFSET_OF(X, Y) __builtin_offsetof(X, Y) #define PRAGMA_DISABLE_DEPRECATION_WARNINGS #define PRAGMA_ENABLE_DEPRECATION_WARNINGS @@ -67,6 +69,7 @@ #define DLLEXPORT __declspec(dllexport) #define DLLIMPORT __declspec(dllimport) +#define USED #define THREADLOCAL __declspec(thread) #define STDCALL __stdcall #define CDECL __cdecl From 3eb690fe58918d31df3ac4361cb672336b93da4b Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 16 Dec 2025 21:13:00 +0200 Subject: [PATCH 5/5] Ensure managed converter functions are exported with optimizations --- .../Bindings/BindingsGenerator.Cpp.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 33f9d3514..570ca4dcc 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -3005,18 +3005,21 @@ namespace Flax.Build.Bindings // Generate MConverter for a structure header.Append("template<>").AppendLine(); - header.AppendFormat("struct DLLEXPORT MConverter<{0}>", fullName).AppendLine(); + header.AppendFormat("struct MConverter<{0}>", fullName).AppendLine(); header.Append('{').AppendLine(); - header.AppendFormat(" MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); + + header.AppendFormat(" DLLEXPORT USED MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.Append(" auto managed = ToManaged(data);").AppendLine(); header.Append(" return MCore::Object::Box((void*)&managed, klass);").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" void Unbox({0}& result, MObject* data)", fullName).AppendLine(); + + header.AppendFormat(" DLLEXPORT USED void Unbox({0}& result, MObject* data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.AppendFormat(" result = ToNative(*reinterpret_cast<{0}*>(MCore::Object::Unbox(data)));", wrapperName).AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" void ToManagedArray(MArray* result, const Span<{0}>& data)", fullName).AppendLine(); + + header.AppendFormat(" DLLEXPORT USED void ToManagedArray(MArray* result, const Span<{0}>& data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.AppendFormat(" MClass* klass = {0}::TypeInitializer.GetClass();", fullName).AppendLine(); header.AppendFormat(" {0}* resultPtr = ({0}*)MCore::Array::GetAddress(result);", wrapperName).AppendLine(); @@ -3026,7 +3029,8 @@ namespace Flax.Build.Bindings header.Append(" MCore::GC::WriteValue(&resultPtr[i], &managed, 1, klass);").AppendLine(); header.Append(" }").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" void ToNativeArray(Span<{0}>& result, const MArray* data)", fullName).AppendLine(); + + header.AppendFormat(" DLLEXPORT USED void ToNativeArray(Span<{0}>& result, const MArray* data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.AppendFormat(" {0}* dataPtr = ({0}*)MCore::Array::GetAddress(data);", wrapperName).AppendLine(); header.Append(" for (int32 i = 0; i < result.Length(); i++)").AppendLine(); @@ -3115,10 +3119,10 @@ namespace Flax.Build.Bindings { // Generate MConverter for a class header.Append("template<>").AppendLine(); - header.AppendFormat("struct DLLEXPORT MConverter<{0}>", fullName).AppendLine(); + header.AppendFormat("struct MConverter<{0}>", fullName).AppendLine(); header.Append('{').AppendLine(); - header.AppendFormat(" static MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED static MObject* Box(const {0}& data, const MClass* klass)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.Append(" MObject* obj = MCore::Object::New(klass);").AppendLine(); for (var i = 0; i < fields.Count; i++) @@ -3138,13 +3142,13 @@ namespace Flax.Build.Bindings header.Append(" return obj;").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" static MObject* Box(const {0}& data)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED static MObject* Box(const {0}& data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.AppendFormat(" MClass* klass = {0}::TypeInitializer.GetClass();", fullName).AppendLine(); header.Append(" return Box(data, klass);").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" static void Unbox({0}& result, MObject* obj)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED static void Unbox({0}& result, MObject* obj)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.Append(" MClass* klass = MCore::Object::GetClass(obj);").AppendLine(); header.Append(" void* v = nullptr;").AppendLine(); @@ -3166,20 +3170,20 @@ namespace Flax.Build.Bindings } header.Append(" }").AppendLine(); - header.AppendFormat(" static {0} Unbox(MObject* data)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED static {0} Unbox(MObject* data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.AppendFormat(" {0} result;", fullName).AppendLine(); header.Append(" Unbox(result, data);").AppendLine(); header.Append(" return result;").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" void ToManagedArray(MArray* result, const Span<{0}>& data)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED void ToManagedArray(MArray* result, const Span<{0}>& data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.Append(" for (int32 i = 0; i < data.Length(); i++)").AppendLine(); header.Append(" MCore::GC::WriteArrayRef(result, Box(data[i]), i);").AppendLine(); header.Append(" }").AppendLine(); - header.AppendFormat(" void ToNativeArray(Span<{0}>& result, const MArray* data)", fullName).AppendLine(); + header.AppendFormat(" DLLEXPORT USED void ToNativeArray(Span<{0}>& result, const MArray* data)", fullName).AppendLine(); header.Append(" {").AppendLine(); header.Append(" MObject** dataPtr = (MObject**)MCore::Array::GetAddress(data);").AppendLine(); header.Append(" for (int32 i = 0; i < result.Length(); i++)").AppendLine();