feat(rendering): add managed SRP renderer runtime

This commit is contained in:
2026-04-19 00:05:29 +08:00
parent a57b322bc7
commit b989edca91
50 changed files with 5732 additions and 171 deletions

View File

@@ -11,6 +11,7 @@
#include "Input/InputManager.h"
#include "Physics/PhysicsWorld.h"
#include "Rendering/Execution/CameraFramePlan.h"
#include "Rendering/GraphicsSettingsState.h"
#include "Rendering/Internal/RenderPipelineFactory.h"
#include "Rendering/Passes/BuiltinVectorFullscreenPass.h"
#include "Rendering/Planning/FullscreenPassDesc.h"
@@ -149,6 +150,84 @@ void UnregisterManagedScriptableRenderContextState(uint64_t handle) {
GetManagedScriptableRenderContextRegistry().erase(handle);
}
const Rendering::RenderCameraData& ResolveManagedScriptableRenderContextCameraData(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->sceneData.cameraData;
}
static const Rendering::RenderCameraData kDefaultCameraData = {};
return kDefaultCameraData;
}
const Rendering::RenderLightingData& ResolveManagedScriptableRenderContextLightingData(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->sceneData.lighting;
}
static const Rendering::RenderLightingData kDefaultLightingData = {};
return kDefaultLightingData;
}
const Rendering::RenderEnvironmentData&
ResolveManagedScriptableRenderContextEnvironmentData(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->sceneData.environment;
}
static const Rendering::RenderEnvironmentData kDefaultEnvironmentData = {};
return kDefaultEnvironmentData;
}
const Rendering::ResolvedFinalColorPolicy&
ResolveManagedScriptableRenderContextFinalColorPolicy(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->finalColorPolicy;
}
static const Rendering::ResolvedFinalColorPolicy
kDefaultFinalColorPolicy = {};
return kDefaultFinalColorPolicy;
}
Rendering::CameraFrameColorSource
ResolveManagedScriptableRenderContextStageColorSource(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->stageColorSource;
}
return Rendering::CameraFrameColorSource::ExplicitSurface;
}
bool ResolveManagedScriptableRenderContextUsesGraphManagedOutputColor(
const ManagedScriptableRenderContextState* state) {
return state != nullptr &&
state->graphContext != nullptr &&
state->graphContext->usesGraphManagedOutputColor;
}
const Rendering::DirectionalShadowRenderPlan&
ResolveManagedScriptableRenderContextDirectionalShadowPlan(
const ManagedScriptableRenderContextState* state) {
if (state != nullptr &&
state->graphContext != nullptr) {
return state->graphContext->directionalShadowPlan;
}
static const Rendering::DirectionalShadowRenderPlan
kDefaultDirectionalShadowPlan = {};
return kDefaultDirectionalShadowPlan;
}
uint64_t& GetManagedScriptableRenderPipelineCameraRequestContextNextHandle() {
static uint64_t nextHandle = 1;
return nextHandle;
@@ -305,12 +384,12 @@ MonoScriptRuntime* GetActiveMonoScriptRuntime() {
void ClearManagedRenderPipelineSelection(MonoScriptRuntime* runtime) {
const Rendering::Pipelines::ManagedRenderPipelineAssetDescriptor descriptor =
Rendering::Pipelines::GetManagedRenderPipelineAssetDescriptor();
Rendering::GetGraphicsSettingsState().GetRenderPipelineAssetDescriptor();
if (runtime != nullptr && descriptor.managedAssetHandle != 0u) {
runtime->ReleaseExternalManagedObject(descriptor.managedAssetHandle);
}
Rendering::Pipelines::ClearManagedRenderPipelineAssetDescriptor();
Rendering::GetGraphicsSettingsState().ClearRenderPipelineAssetDescriptor();
}
bool TryUnboxManagedBoolean(MonoObject* boxedValue, bool& outValue) {
@@ -2731,7 +2810,7 @@ mono_bool InternalCall_Physics_Raycast(
void InternalCall_Rendering_SetRenderPipelineAsset(MonoObject* assetObject) {
MonoScriptRuntime* const runtime = GetActiveMonoScriptRuntime();
const Rendering::Pipelines::ManagedRenderPipelineAssetDescriptor currentDescriptor =
Rendering::Pipelines::GetManagedRenderPipelineAssetDescriptor();
Rendering::GetGraphicsSettingsState().GetRenderPipelineAssetDescriptor();
if (assetObject == nullptr) {
ClearManagedRenderPipelineSelection(runtime);
@@ -2775,7 +2854,8 @@ void InternalCall_Rendering_SetRenderPipelineAsset(MonoObject* assetObject) {
currentDescriptor.managedAssetHandle);
}
Rendering::Pipelines::SetManagedRenderPipelineAssetDescriptor(descriptor);
Rendering::GetGraphicsSettingsState().SetRenderPipelineAssetDescriptor(
descriptor);
}
MonoObject* InternalCall_Rendering_GetRenderPipelineAsset() {
@@ -2784,13 +2864,21 @@ MonoObject* InternalCall_Rendering_GetRenderPipelineAsset() {
return nullptr;
}
const Rendering::Pipelines::ManagedRenderPipelineAssetDescriptor descriptor =
Rendering::Pipelines::GetManagedRenderPipelineAssetDescriptor();
if (!descriptor.IsValid() ||
descriptor.managedAssetHandle == 0u) {
Rendering::Pipelines::ManagedRenderPipelineAssetDescriptor descriptor =
Rendering::GetGraphicsSettingsState().GetRenderPipelineAssetDescriptor();
if (!descriptor.IsValid()) {
return nullptr;
}
if (descriptor.managedAssetHandle == 0u) {
if (!runtime->TryEnsureManagedRenderPipelineAssetHandle(descriptor)) {
return nullptr;
}
Rendering::GetGraphicsSettingsState().SetRenderPipelineAssetDescriptor(
descriptor);
}
return runtime->GetExternalManagedObject(
descriptor.managedAssetHandle);
}
@@ -2804,6 +2892,512 @@ int32_t InternalCall_Rendering_ScriptableRenderContext_GetStage(
: static_cast<int32_t>(Rendering::CameraFrameStage::MainScene);
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetStageColorSource(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextStageColorSource(state));
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetStageUsesGraphManagedOutputColor(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextUsesGraphManagedOutputColor(
state)
? 1
: 0;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowEnabled(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.enabled
? 1
: 0;
}
void InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowViewProjection(
uint64_t nativeHandle,
XCEngine::Math::Matrix4x4* outViewProjection) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outViewProjection =
ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.cameraData.viewProjection;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowOrthographicHalfExtent(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.orthographicHalfExtent;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowNearClipPlane(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.nearClipPlane;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowFarClipPlane(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.farClipPlane;
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapWidth(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.mapWidth);
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapHeight(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.mapHeight);
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowWorldTexelSize(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.texelWorldSize;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowReceiverDepthBias(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.sampling.receiverDepthBias;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowNormalBiasScale(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.sampling.normalBiasScale;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowStrength(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.sampling.shadowStrength;
}
float InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasFactor(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.casterBias.depthBiasFactor;
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasUnits(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextDirectionalShadowPlan(state)
.casterBias.depthBiasUnits;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraView(
uint64_t nativeHandle,
XCEngine::Math::Matrix4x4* outView) {
if (outView == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outView =
ResolveManagedScriptableRenderContextCameraData(state).view;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraProjection(
uint64_t nativeHandle,
XCEngine::Math::Matrix4x4* outProjection) {
if (outProjection == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outProjection =
ResolveManagedScriptableRenderContextCameraData(state).projection;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraViewProjection(
uint64_t nativeHandle,
XCEngine::Math::Matrix4x4* outViewProjection) {
if (outViewProjection == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outViewProjection =
ResolveManagedScriptableRenderContextCameraData(state).viewProjection;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldPosition(
uint64_t nativeHandle,
XCEngine::Math::Vector3* outWorldPosition) {
if (outWorldPosition == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outWorldPosition =
ResolveManagedScriptableRenderContextCameraData(state).worldPosition;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldRight(
uint64_t nativeHandle,
XCEngine::Math::Vector3* outWorldRight) {
if (outWorldRight == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outWorldRight =
ResolveManagedScriptableRenderContextCameraData(state).worldRight;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldUp(
uint64_t nativeHandle,
XCEngine::Math::Vector3* outWorldUp) {
if (outWorldUp == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outWorldUp =
ResolveManagedScriptableRenderContextCameraData(state).worldUp;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldForward(
uint64_t nativeHandle,
XCEngine::Math::Vector3* outWorldForward) {
if (outWorldForward == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outWorldForward =
ResolveManagedScriptableRenderContextCameraData(state).worldForward;
}
void InternalCall_Rendering_ScriptableRenderContext_GetCameraClearColor(
uint64_t nativeHandle,
XCEngine::Math::Color* outClearColor) {
if (outClearColor == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outClearColor =
ResolveManagedScriptableRenderContextCameraData(state).clearColor;
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetCameraClearFlags(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextCameraData(state).clearFlags);
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetCameraPerspectiveProjection(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.perspectiveProjection
? 1
: 0;
}
float InternalCall_Rendering_ScriptableRenderContext_GetCameraVerticalFovRadians(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.verticalFovRadians;
}
float InternalCall_Rendering_ScriptableRenderContext_GetCameraOrthographicSize(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.orthographicSize;
}
float InternalCall_Rendering_ScriptableRenderContext_GetCameraAspectRatio(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.aspectRatio;
}
float InternalCall_Rendering_ScriptableRenderContext_GetCameraNearClipPlane(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.nearClipPlane;
}
float InternalCall_Rendering_ScriptableRenderContext_GetCameraFarClipPlane(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextCameraData(state)
.farClipPlane;
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetCameraViewportWidth(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextCameraData(state).viewportWidth);
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetCameraViewportHeight(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextCameraData(state).viewportHeight);
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightEnabled(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextLightingData(state)
.mainDirectionalLight.enabled
? 1
: 0;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightCastsShadows(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextLightingData(state)
.mainDirectionalLight.castsShadows
? 1
: 0;
}
void InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightDirection(
uint64_t nativeHandle,
XCEngine::Math::Vector3* outDirection) {
if (outDirection == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outDirection = ResolveManagedScriptableRenderContextLightingData(state)
.mainDirectionalLight.direction;
}
void InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightColor(
uint64_t nativeHandle,
XCEngine::Math::Color* outColor) {
if (outColor == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outColor = ResolveManagedScriptableRenderContextLightingData(state)
.mainDirectionalLight.color;
}
float
InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightIntensity(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextLightingData(state)
.mainDirectionalLight.intensity;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetHasMainDirectionalShadow(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextLightingData(state)
.HasMainDirectionalShadow()
? 1
: 0;
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetAdditionalLightCount(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextLightingData(state)
.additionalLightCount);
}
int32_t InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentMode(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextEnvironmentData(state).mode);
}
void InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxTopColor(
uint64_t nativeHandle,
XCEngine::Math::Color* outColor) {
if (outColor == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outColor = ResolveManagedScriptableRenderContextEnvironmentData(state)
.skybox.topColor;
}
void InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxHorizonColor(
uint64_t nativeHandle,
XCEngine::Math::Color* outColor) {
if (outColor == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outColor = ResolveManagedScriptableRenderContextEnvironmentData(state)
.skybox.horizonColor;
}
void InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxBottomColor(
uint64_t nativeHandle,
XCEngine::Math::Color* outColor) {
if (outColor == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outColor = ResolveManagedScriptableRenderContextEnvironmentData(state)
.skybox.bottomColor;
}
int32_t
InternalCall_Rendering_ScriptableRenderContext_GetFinalColorOutputTransferMode(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.outputTransferMode);
}
int32_t
InternalCall_Rendering_ScriptableRenderContext_GetFinalColorExposureMode(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.exposureMode);
}
float InternalCall_Rendering_ScriptableRenderContext_GetFinalColorExposureValue(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.exposureValue;
}
int32_t
InternalCall_Rendering_ScriptableRenderContext_GetFinalColorToneMappingMode(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return static_cast<int32_t>(
ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.toneMappingMode);
}
void InternalCall_Rendering_ScriptableRenderContext_GetFinalColorScale(
uint64_t nativeHandle,
XCEngine::Math::Vector4* outScale) {
if (outScale == nullptr) {
return;
}
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
*outScale = ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.finalColorScale;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetFinalColorHasPipelineDefaults(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.hasPipelineDefaults
? 1
: 0;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_GetFinalColorHasCameraOverrides(
uint64_t nativeHandle) {
const ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
return ResolveManagedScriptableRenderContextFinalColorPolicy(state)
.hasCameraOverrides
? 1
: 0;
}
mono_bool InternalCall_Rendering_ScriptableRenderContext_RecordScene(
uint64_t nativeHandle) {
ManagedScriptableRenderContextState* const state =
@@ -3115,6 +3709,56 @@ void RegisterInternalCalls() {
mono_add_internal_call("XCEngine.InternalCalls::Rendering_SetRenderPipelineAsset", reinterpret_cast<const void*>(&InternalCall_Rendering_SetRenderPipelineAsset));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_GetRenderPipelineAsset", reinterpret_cast<const void*>(&InternalCall_Rendering_GetRenderPipelineAsset));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetStage", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetStage));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetStageColorSource", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetStageColorSource));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetStageUsesGraphManagedOutputColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetStageUsesGraphManagedOutputColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowEnabled", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowEnabled));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowViewProjection", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowViewProjection));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowOrthographicHalfExtent", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowOrthographicHalfExtent));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowNearClipPlane", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowNearClipPlane));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowFarClipPlane", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowFarClipPlane));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapWidth", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapWidth));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapHeight", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowMapHeight));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowWorldTexelSize", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowWorldTexelSize));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowReceiverDepthBias", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowReceiverDepthBias));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowNormalBiasScale", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowNormalBiasScale));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowStrength", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowStrength));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasFactor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasFactor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasUnits", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalShadowDepthBiasUnits));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraView", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraView));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraProjection", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraProjection));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraViewProjection", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraViewProjection));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraWorldPosition", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldPosition));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraWorldRight", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldRight));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraWorldUp", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldUp));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraWorldForward", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraWorldForward));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraClearColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraClearColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraClearFlags", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraClearFlags));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraPerspectiveProjection", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraPerspectiveProjection));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraVerticalFovRadians", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraVerticalFovRadians));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraOrthographicSize", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraOrthographicSize));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraAspectRatio", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraAspectRatio));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraNearClipPlane", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraNearClipPlane));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraFarClipPlane", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraFarClipPlane));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraViewportWidth", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraViewportWidth));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetCameraViewportHeight", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetCameraViewportHeight));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalLightEnabled", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightEnabled));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalLightCastsShadows", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightCastsShadows));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalLightDirection", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightDirection));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalLightColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetMainDirectionalLightIntensity", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetMainDirectionalLightIntensity));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetHasMainDirectionalShadow", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetHasMainDirectionalShadow));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetAdditionalLightCount", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetAdditionalLightCount));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetEnvironmentMode", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentMode));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetEnvironmentSkyboxTopColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxTopColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetEnvironmentSkyboxHorizonColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxHorizonColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetEnvironmentSkyboxBottomColor", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetEnvironmentSkyboxBottomColor));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorOutputTransferMode", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorOutputTransferMode));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorExposureMode", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorExposureMode));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorExposureValue", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorExposureValue));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorToneMappingMode", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorToneMappingMode));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorScale", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorScale));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorHasPipelineDefaults", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorHasPipelineDefaults));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetFinalColorHasCameraOverrides", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetFinalColorHasCameraOverrides));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordScene", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordScene));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordScenePhase", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordScenePhase));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordSceneInjectionPoint", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordSceneInjectionPoint));
@@ -3260,6 +3904,30 @@ bool MonoScriptRuntime::TryGetAvailableScriptClasses(
return true;
}
bool MonoScriptRuntime::TryGetAvailableRenderPipelineAssetClasses(
std::vector<ScriptClassDescriptor>& outClasses) const {
outClasses.clear();
if (!m_initialized) {
return false;
}
outClasses = m_renderPipelineAssetClasses;
std::sort(
outClasses.begin(),
outClasses.end(),
[](const ScriptClassDescriptor& lhs, const ScriptClassDescriptor& rhs) {
if (lhs.assemblyName != rhs.assemblyName) {
return lhs.assemblyName < rhs.assemblyName;
}
if (lhs.namespaceName != rhs.namespaceName) {
return lhs.namespaceName < rhs.namespaceName;
}
return lhs.className < rhs.className;
});
return true;
}
std::vector<std::string> MonoScriptRuntime::GetScriptClassNames(const std::string& assemblyName) const {
std::vector<ScriptClassDescriptor> classes;
if (!TryGetAvailableScriptClasses(classes)) {
@@ -3898,6 +4566,9 @@ bool MonoScriptRuntime::DiscoverScriptClasses() {
}
DiscoverScriptClassesInImage(m_settings.appAssemblyName, m_appImage);
DiscoverRenderPipelineAssetClassesInImage(
m_settings.appAssemblyName,
m_appImage);
return true;
}
@@ -3972,6 +4643,38 @@ void MonoScriptRuntime::DiscoverScriptClassesInImage(const std::string& assembly
}
}
void MonoScriptRuntime::DiscoverRenderPipelineAssetClassesInImage(
const std::string& assemblyName,
MonoImage* image) {
if (!image || m_scriptableRenderPipelineAssetClass == nullptr) {
return;
}
const int typeCount = mono_image_get_table_rows(image, MONO_TABLE_TYPEDEF);
for (int index = 1; index <= typeCount; ++index) {
const uint32_t typeToken =
mono_metadata_make_token(MONO_TABLE_TYPEDEF, index);
MonoClass* monoClass = mono_class_get(image, typeToken);
if (monoClass == nullptr ||
monoClass == m_scriptableRenderPipelineAssetClass ||
!IsMonoClassOrSubclass(
monoClass,
m_scriptableRenderPipelineAssetClass)) {
continue;
}
if ((mono_class_get_flags(monoClass) & MONO_TYPE_ATTR_ABSTRACT) != 0) {
continue;
}
m_renderPipelineAssetClasses.push_back(
ScriptClassDescriptor{
assemblyName,
SafeString(mono_class_get_namespace(monoClass)),
SafeString(mono_class_get_name(monoClass))});
}
}
bool MonoScriptRuntime::IsMonoBehaviourSubclass(MonoClass* monoClass) const {
if (!monoClass || !m_monoBehaviourClass || monoClass == m_monoBehaviourClass) {
return false;
@@ -4302,6 +5005,45 @@ bool MonoScriptRuntime::IsScriptableRenderPipelineAssetObject(
m_scriptableRenderPipelineAssetClass);
}
bool MonoScriptRuntime::TryEnsureManagedRenderPipelineAssetHandle(
Rendering::Pipelines::ManagedRenderPipelineAssetDescriptor& ioDescriptor) {
if (!m_initialized || !ioDescriptor.IsValid()) {
return false;
}
if (ioDescriptor.managedAssetHandle != 0u) {
MonoObject* const assetObject =
GetExternalManagedObject(ioDescriptor.managedAssetHandle);
if (IsScriptableRenderPipelineAssetObject(assetObject)) {
return true;
}
ioDescriptor.managedAssetHandle = 0u;
}
MonoClass* assetClass = nullptr;
if (!ResolveManagedClass(
ioDescriptor.assemblyName,
ioDescriptor.namespaceName,
ioDescriptor.className,
assetClass) ||
assetClass == nullptr) {
return false;
}
if (!IsMonoClassOrSubclass(
assetClass,
m_scriptableRenderPipelineAssetClass)) {
SetError(
"Managed render pipeline asset must derive from ScriptableRenderPipelineAsset: " +
ioDescriptor.GetFullName() + ".");
return false;
}
return CreateExternalManagedObject(assetClass, ioDescriptor.managedAssetHandle) &&
ioDescriptor.managedAssetHandle != 0u;
}
void MonoScriptRuntime::DestroyExternalManagedObject(uint32_t gcHandle) {
if (gcHandle == 0) {
return;
@@ -4483,10 +5225,20 @@ MonoMethod* MonoScriptRuntime::ResolveManagedMethod(
}
SetCurrentDomain();
return mono_class_get_method_from_name(
monoClass,
methodName,
parameterCount);
for (MonoClass* currentClass = monoClass;
currentClass != nullptr;
currentClass = mono_class_get_parent(currentClass)) {
if (MonoMethod* const method =
mono_class_get_method_from_name(
currentClass,
methodName,
parameterCount);
method != nullptr) {
return method;
}
}
return nullptr;
}
MonoMethod* MonoScriptRuntime::ResolveManagedMethod(
@@ -5118,6 +5870,7 @@ void MonoScriptRuntime::ClearExternalManagedObjects() {
void MonoScriptRuntime::ClearClassCache() {
m_classes.clear();
m_renderPipelineAssetClasses.clear();
}
bool MonoScriptRuntime::InvokeManagedMethod(