Bridge managed render funcs to command buffers

This commit is contained in:
2026-04-27 16:11:54 +08:00
parent 2e6643b4d1
commit 048ca7b362
10 changed files with 697 additions and 27 deletions

View File

@@ -549,7 +549,8 @@ namespace XCEngine
internal static extern bool
Rendering_ScriptableRenderContext_SetRasterPassManagedRenderFuncExecution(
ulong nativeHandle,
ulong rasterPassHandle);
ulong rasterPassHandle,
Action<Rendering.RenderGraphRasterContext> renderFunc);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool
@@ -557,6 +558,12 @@ namespace XCEngine
ulong nativeHandle,
ulong rasterPassHandle);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool
Rendering_CommandBuffer_ClearRenderTarget(
ulong nativeHandle,
ref Color color);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int
Rendering_ScriptableRenderPipelinePlanningContext_GetRendererIndex(

View File

@@ -1,3 +1,5 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class CommandBuffer
@@ -9,10 +11,33 @@ namespace XCEngine.Rendering
public CommandBuffer(
string name)
: this(
name,
0ul)
{
}
internal CommandBuffer(
string name,
ulong nativeHandle)
{
this.name = name ?? string.Empty;
m_nativeHandle = nativeHandle;
}
public string name { get; set; }
public bool isValid => m_nativeHandle != 0ul;
public bool ClearRenderTarget(
Color color)
{
return m_nativeHandle != 0ul &&
InternalCalls.Rendering_CommandBuffer_ClearRenderTarget(
m_nativeHandle,
ref color);
}
private readonly ulong m_nativeHandle;
}
}

View File

@@ -373,17 +373,12 @@ namespace XCEngine.Rendering
break;
case RenderGraphRasterPassExecutionKind
.ManagedRenderFunc:
// Managed command buffers are not bridged into native
// graph execution yet, so the render func is invoked
// during recording while native records the declared IO.
m_renderFunc(
new RenderGraphRasterContext(
new CommandBuffer(m_passName)));
configuredExecution =
InternalCalls
.Rendering_ScriptableRenderContext_SetRasterPassManagedRenderFuncExecution(
m_context.nativeHandle,
nativePassHandle);
nativePassHandle,
m_renderFunc);
break;
default:
configuredExecution = false;
@@ -501,5 +496,24 @@ namespace XCEngine.Rendering
return false;
}
internal static bool InvokeManagedRenderFunc(
Action<RenderGraphRasterContext> renderFunc,
string passName,
ulong commandBufferHandle)
{
if (renderFunc == null ||
commandBufferHandle == 0ul)
{
return false;
}
renderFunc(
new RenderGraphRasterContext(
new CommandBuffer(
passName,
commandBufferHandle)));
return true;
}
}
}