docs(editor): sync script assembly builder api docs

This commit is contained in:
2026-04-12 22:50:50 +08:00
parent a660fc489a
commit 89590242bd
24 changed files with 285 additions and 1813 deletions

View File

@@ -65,22 +65,6 @@ const Resources::ShaderPass* FindCompatibleComputePass(
: nullptr;
}
const Resources::ShaderPass* FindCompatibleGraphicsPass(
const Resources::Shader& shader,
const Containers::String& passName,
const Resources::ShaderKeywordSet& keywordSet,
Resources::ShaderBackend backend) {
const Resources::ShaderPass* shaderPass = shader.FindPass(passName);
if (shaderPass == nullptr) {
return nullptr;
}
return shader.FindVariant(passName, Resources::ShaderType::Vertex, backend, keywordSet) != nullptr &&
shader.FindVariant(passName, Resources::ShaderType::Fragment, backend, keywordSet) != nullptr
? shaderPass
: nullptr;
}
RHI::GraphicsPipelineDesc CreatePipelineDesc(
RHI::RHIType backendType,
RHI::RHIPipelineLayout* pipelineLayout,
@@ -121,44 +105,6 @@ RHI::GraphicsPipelineDesc CreatePipelineDesc(
return pipelineDesc;
}
RHI::GraphicsPipelineDesc CreateCompositePipelineDesc(
RHI::RHIType backendType,
RHI::RHIPipelineLayout* pipelineLayout,
const Resources::Shader& shader,
const Resources::ShaderPass& shaderPass,
const Containers::String& passName,
const RenderSurface& surface) {
RHI::GraphicsPipelineDesc pipelineDesc = {};
pipelineDesc.pipelineLayout = pipelineLayout;
pipelineDesc.topologyType = static_cast<uint32_t>(RHI::PrimitiveTopologyType::Triangle);
::XCEngine::Rendering::Internal::ApplySingleColorAttachmentPropertiesToGraphicsPipelineDesc(surface, pipelineDesc);
pipelineDesc.depthStencilFormat =
static_cast<uint32_t>(::XCEngine::Rendering::Internal::ResolveSurfaceDepthFormat(surface));
ApplyResolvedRenderState(&shaderPass, nullptr, pipelineDesc);
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Internal::ToShaderBackend(backendType);
if (const Resources::ShaderStageVariant* vertexVariant =
shader.FindVariant(passName, Resources::ShaderType::Vertex, backend)) {
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
shader.GetPath(),
shaderPass,
backend,
*vertexVariant,
pipelineDesc.vertexShader);
}
if (const Resources::ShaderStageVariant* fragmentVariant =
shader.FindVariant(passName, Resources::ShaderType::Fragment, backend)) {
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
shader.GetPath(),
shaderPass,
backend,
*fragmentVariant,
pipelineDesc.fragmentShader);
}
return pipelineDesc;
}
RHI::ComputePipelineDesc CreateComputePipelineDesc(
RHI::RHIType backendType,
RHI::RHIPipelineLayout* pipelineLayout,
@@ -262,10 +208,6 @@ void BindDescriptorSetRanges(
}
}
RHI::Format ResolveGaussianAccumulationFormat() {
return RHI::Format::R16G16B16A16_Float;
}
} // namespace
BuiltinGaussianSplatPass::~BuiltinGaussianSplatPass() {
@@ -362,31 +304,10 @@ bool BuiltinGaussianSplatPass::Execute(const RenderPassContext& context) {
return false;
}
if (!EnsureCompositeResources(context.renderContext, context.surface)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to initialize composite resources");
return false;
}
Internal::BuiltinGaussianSplatPassResources::AccumulationSurface* accumulationSurface = nullptr;
if (m_passResources == nullptr ||
!m_passResources->EnsureAccumulationSurface(
m_device,
context.surface.GetWidth(),
context.surface.GetHeight(),
ResolveGaussianAccumulationFormat(),
accumulationSurface) ||
accumulationSurface == nullptr ||
accumulationSurface->renderTargetView == nullptr ||
accumulationSurface->shaderResourceView == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to allocate gaussian accumulation surface");
return false;
}
RHI::RHICommandList* commandList = context.renderContext.commandList;
RHI::RHIResourceView* renderTarget = colorAttachments[0];
commandList->SetRenderTargets(1, &renderTarget, context.surface.GetDepthAttachment());
const RHI::Viewport viewport = {
static_cast<float>(renderArea.x),
static_cast<float>(renderArea.y),
@@ -401,31 +322,9 @@ bool BuiltinGaussianSplatPass::Execute(const RenderPassContext& context) {
renderArea.x + renderArea.width,
renderArea.y + renderArea.height
};
const RHI::Rect clearRects[] = { scissorRect };
const float clearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
RenderSurface accumulationRenderSurface(context.surface.GetWidth(), context.surface.GetHeight());
accumulationRenderSurface.SetColorAttachment(accumulationSurface->renderTargetView);
accumulationRenderSurface.SetDepthAttachment(context.surface.GetDepthAttachment());
accumulationRenderSurface.SetRenderArea(renderArea);
accumulationRenderSurface.SetAutoTransitionEnabled(false);
accumulationRenderSurface.SetSampleDesc(1u, 0u);
commandList->EndRenderPass();
if (accumulationSurface->currentColorState != RHI::ResourceStates::RenderTarget) {
commandList->TransitionBarrier(
accumulationSurface->renderTargetView,
accumulationSurface->currentColorState,
RHI::ResourceStates::RenderTarget);
accumulationSurface->currentColorState = RHI::ResourceStates::RenderTarget;
}
RHI::RHIResourceView* accumulationRenderTarget = accumulationSurface->renderTargetView;
commandList->SetRenderTargets(1, &accumulationRenderTarget, context.surface.GetDepthAttachment());
commandList->SetViewport(viewport);
commandList->SetScissorRect(scissorRect);
commandList->SetPrimitiveTopology(RHI::PrimitiveTopology::TriangleList);
commandList->ClearRenderTarget(accumulationRenderTarget, clearColor, 1u, clearRects);
for (const VisibleGaussianSplatItem& visibleGaussianSplat : context.sceneData.visibleGaussianSplats) {
if (!MarkVisibleGaussianSplatChunks(
@@ -451,23 +350,14 @@ bool BuiltinGaussianSplatPass::Execute(const RenderPassContext& context) {
if (!DrawVisibleGaussianSplat(
context.renderContext,
accumulationRenderSurface,
context.surface,
context.sceneData,
visibleGaussianSplat)) {
return false;
}
}
commandList->EndRenderPass();
if (accumulationSurface->currentColorState != RHI::ResourceStates::PixelShaderResource) {
commandList->TransitionBarrier(
accumulationSurface->shaderResourceView,
accumulationSurface->currentColorState,
RHI::ResourceStates::PixelShaderResource);
accumulationSurface->currentColorState = RHI::ResourceStates::PixelShaderResource;
}
return CompositeAccumulationSurface(context, accumulationSurface->shaderResourceView);
return true;
}
void BuiltinGaussianSplatPass::Shutdown() {
@@ -482,8 +372,6 @@ bool BuiltinGaussianSplatPass::EnsureInitialized(const RenderContext& context) {
if (m_device == context.device &&
m_backendType == context.backendType &&
m_builtinGaussianSplatShader.IsValid() &&
m_builtinGaussianSplatCompositeShader.IsValid() &&
m_builtinGaussianSplatUtilitiesShader.IsValid() &&
m_builtinGaussianSplatMaterial != nullptr) {
return true;
}
@@ -505,16 +393,6 @@ bool BuiltinGaussianSplatPass::CreateResources(const RenderContext& context) {
return false;
}
m_builtinGaussianSplatCompositeShader = Resources::ResourceManager::Get().Load<Resources::Shader>(
Resources::GetBuiltinGaussianSplatCompositeShaderPath());
if (!m_builtinGaussianSplatCompositeShader.IsValid()) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to load builtin gaussian composite shader resource");
DestroyResources();
return false;
}
m_builtinGaussianSplatUtilitiesShader = Resources::ResourceManager::Get().Load<Resources::Shader>(
Resources::GetBuiltinGaussianSplatUtilitiesShaderPath());
if (!m_builtinGaussianSplatUtilitiesShader.IsValid()) {
@@ -537,207 +415,6 @@ bool BuiltinGaussianSplatPass::CreateResources(const RenderContext& context) {
return true;
}
bool BuiltinGaussianSplatPass::EnsureCompositeResources(
const RenderContext& context,
const RenderSurface& surface) {
const RHI::Format renderTargetFormat =
::XCEngine::Rendering::Internal::ResolveSurfaceColorFormat(surface, 0u);
const Core::uint32 sampleCount =
::XCEngine::Rendering::Internal::ResolveSurfaceSampleCount(surface);
const Core::uint32 sampleQuality =
::XCEngine::Rendering::Internal::ResolveSurfaceSampleQuality(surface);
if (m_compositeResources.pipelineLayout != nullptr &&
m_compositeResources.pipelineState != nullptr &&
m_compositeResources.textureSet.set != nullptr &&
m_compositeResources.renderTargetFormat == renderTargetFormat &&
m_compositeResources.sampleCount == sampleCount &&
m_compositeResources.sampleQuality == sampleQuality) {
return true;
}
DestroyCompositeResources();
return CreateCompositeResources(context, surface);
}
bool BuiltinGaussianSplatPass::CreateCompositeResources(
const RenderContext& context,
const RenderSurface& surface) {
if (!context.IsValid() || !m_builtinGaussianSplatCompositeShader.IsValid()) {
return false;
}
RHI::Format renderTargetFormat = RHI::Format::Unknown;
if (!::XCEngine::Rendering::Internal::TryResolveSingleColorAttachmentFormat(surface, renderTargetFormat)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass composite requires a valid single-color destination surface");
return false;
}
const Containers::String compositePassName("GaussianComposite");
const Resources::Shader& shader = *m_builtinGaussianSplatCompositeShader.Get();
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Internal::ToShaderBackend(context.backendType);
const Resources::ShaderPass* compositePass = FindCompatibleGraphicsPass(
shader,
compositePassName,
Resources::ShaderKeywordSet(),
backend);
if (compositePass == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to resolve gaussian composite shader pass");
return false;
}
RHI::DescriptorSetLayoutBinding textureBinding = {};
textureBinding.binding = 0u;
textureBinding.type = static_cast<uint32_t>(RHI::DescriptorType::SRV);
textureBinding.count = 1u;
textureBinding.visibility = static_cast<uint32_t>(RHI::ShaderVisibility::All);
RHI::DescriptorSetLayoutDesc textureLayout = {};
textureLayout.bindings = &textureBinding;
textureLayout.bindingCount = 1u;
RHI::RHIPipelineLayoutDesc pipelineLayoutDesc = {};
pipelineLayoutDesc.setLayouts = &textureLayout;
pipelineLayoutDesc.setLayoutCount = 1u;
m_compositeResources.pipelineLayout = m_device->CreatePipelineLayout(pipelineLayoutDesc);
if (m_compositeResources.pipelineLayout == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to create gaussian composite pipeline layout");
DestroyCompositeResources();
return false;
}
RHI::DescriptorPoolDesc poolDesc = {};
poolDesc.type = RHI::DescriptorHeapType::CBV_SRV_UAV;
poolDesc.descriptorCount = 1u;
poolDesc.shaderVisible = true;
m_compositeResources.textureSet.pool = m_device->CreateDescriptorPool(poolDesc);
if (m_compositeResources.textureSet.pool == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to create gaussian composite descriptor pool");
DestroyCompositeResources();
return false;
}
m_compositeResources.textureSet.set =
m_compositeResources.textureSet.pool->AllocateSet(textureLayout);
if (m_compositeResources.textureSet.set == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to allocate gaussian composite descriptor set");
DestroyCompositeResources();
return false;
}
m_compositeResources.pipelineState = m_device->CreatePipelineState(
CreateCompositePipelineDesc(
m_backendType,
m_compositeResources.pipelineLayout,
shader,
*compositePass,
compositePassName,
surface));
if (m_compositeResources.pipelineState == nullptr || !m_compositeResources.pipelineState->IsValid()) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass failed to create gaussian composite pipeline state");
DestroyCompositeResources();
return false;
}
m_compositeResources.renderTargetFormat = renderTargetFormat;
m_compositeResources.sampleCount =
::XCEngine::Rendering::Internal::ResolveSurfaceSampleCount(surface);
m_compositeResources.sampleQuality =
::XCEngine::Rendering::Internal::ResolveSurfaceSampleQuality(surface);
return true;
}
void BuiltinGaussianSplatPass::DestroyCompositeResources() {
m_compositeResources.boundAccumulationView = nullptr;
if (m_compositeResources.pipelineState != nullptr) {
m_compositeResources.pipelineState->Shutdown();
delete m_compositeResources.pipelineState;
m_compositeResources.pipelineState = nullptr;
}
DestroyOwnedDescriptorSet(m_compositeResources.textureSet);
if (m_compositeResources.pipelineLayout != nullptr) {
m_compositeResources.pipelineLayout->Shutdown();
delete m_compositeResources.pipelineLayout;
m_compositeResources.pipelineLayout = nullptr;
}
m_compositeResources.renderTargetFormat = RHI::Format::Unknown;
m_compositeResources.sampleCount = 1u;
m_compositeResources.sampleQuality = 0u;
}
bool BuiltinGaussianSplatPass::CompositeAccumulationSurface(
const RenderPassContext& context,
RHI::RHIResourceView* accumulationTextureView) {
if (m_compositeResources.pipelineLayout == nullptr ||
m_compositeResources.pipelineState == nullptr ||
m_compositeResources.textureSet.set == nullptr ||
accumulationTextureView == nullptr) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinGaussianSplatPass composite failed: composite resources are incomplete");
return false;
}
const std::vector<RHI::RHIResourceView*>& colorAttachments = context.surface.GetColorAttachments();
if (colorAttachments.empty() || colorAttachments[0] == nullptr) {
return false;
}
if (m_compositeResources.boundAccumulationView != accumulationTextureView) {
m_compositeResources.textureSet.set->Update(0u, accumulationTextureView);
m_compositeResources.boundAccumulationView = accumulationTextureView;
}
const Math::RectInt renderArea = context.surface.GetRenderArea();
const RHI::Viewport viewport = {
static_cast<float>(renderArea.x),
static_cast<float>(renderArea.y),
static_cast<float>(renderArea.width),
static_cast<float>(renderArea.height),
0.0f,
1.0f
};
const RHI::Rect scissorRect = {
renderArea.x,
renderArea.y,
renderArea.x + renderArea.width,
renderArea.y + renderArea.height
};
RHI::RHICommandList* commandList = context.renderContext.commandList;
RHI::RHIResourceView* renderTarget = colorAttachments[0];
commandList->SetRenderTargets(1u, &renderTarget, context.surface.GetDepthAttachment());
commandList->SetViewport(viewport);
commandList->SetScissorRect(scissorRect);
commandList->SetPrimitiveTopology(RHI::PrimitiveTopology::TriangleList);
commandList->SetPipelineState(m_compositeResources.pipelineState);
RHI::RHIDescriptorSet* descriptorSet = m_compositeResources.textureSet.set;
commandList->SetGraphicsDescriptorSets(
0u,
1u,
&descriptorSet,
m_compositeResources.pipelineLayout);
commandList->Draw(3u, 1u, 0u, 0u);
return true;
}
void BuiltinGaussianSplatPass::DestroyResources() {
if (m_passResources != nullptr) {
m_passResources->Shutdown();
@@ -773,11 +450,8 @@ void BuiltinGaussianSplatPass::DestroyResources() {
}
m_passResourceLayouts.clear();
DestroyCompositeResources();
m_builtinGaussianSplatMaterial.reset();
m_builtinGaussianSplatUtilitiesShader.Reset();
m_builtinGaussianSplatCompositeShader.Reset();
m_builtinGaussianSplatShader.Reset();
m_device = nullptr;
m_backendType = RHI::RHIType::D3D12;
@@ -1474,10 +1148,10 @@ bool BuiltinGaussianSplatPass::MarkVisibleGaussianSplatChunks(
sceneData.cameraData.projection,
sceneData.cameraData.view,
visibleGaussianSplat.localToWorld.Transpose(),
visibleGaussianSplat.localToWorld.Inverse().Transpose(),
visibleGaussianSplat.localToWorld.Inverse(),
Math::Vector4(sceneData.cameraData.worldRight, 0.0f),
Math::Vector4(sceneData.cameraData.worldUp, 0.0f),
Math::Vector4(sceneData.cameraData.worldPosition, sceneData.cameraData.nearClipPlane),
Math::Vector4(sceneData.cameraData.worldPosition, 0.0f),
Math::Vector4(
static_cast<float>(sceneData.cameraData.viewportWidth),
static_cast<float>(sceneData.cameraData.viewportHeight),
@@ -1651,10 +1325,10 @@ bool BuiltinGaussianSplatPass::PrepareVisibleGaussianSplat(
sceneData.cameraData.projection,
sceneData.cameraData.view,
visibleGaussianSplat.localToWorld.Transpose(),
visibleGaussianSplat.localToWorld.Inverse().Transpose(),
visibleGaussianSplat.localToWorld.Inverse(),
Math::Vector4(sceneData.cameraData.worldRight, 0.0f),
Math::Vector4(sceneData.cameraData.worldUp, 0.0f),
Math::Vector4(sceneData.cameraData.worldPosition, sceneData.cameraData.nearClipPlane),
Math::Vector4(sceneData.cameraData.worldPosition, 0.0f),
Math::Vector4(
static_cast<float>(sceneData.cameraData.viewportWidth),
static_cast<float>(sceneData.cameraData.viewportHeight),
@@ -1835,10 +1509,10 @@ bool BuiltinGaussianSplatPass::SortVisibleGaussianSplat(
sceneData.cameraData.projection,
sceneData.cameraData.view,
visibleGaussianSplat.localToWorld.Transpose(),
visibleGaussianSplat.localToWorld.Inverse().Transpose(),
visibleGaussianSplat.localToWorld.Inverse(),
Math::Vector4(sceneData.cameraData.worldRight, 0.0f),
Math::Vector4(sceneData.cameraData.worldUp, 0.0f),
Math::Vector4(sceneData.cameraData.worldPosition, sceneData.cameraData.nearClipPlane),
Math::Vector4(sceneData.cameraData.worldPosition, 0.0f),
Math::Vector4(
static_cast<float>(sceneData.cameraData.viewportWidth),
static_cast<float>(sceneData.cameraData.viewportHeight),
@@ -2008,10 +1682,10 @@ bool BuiltinGaussianSplatPass::DrawVisibleGaussianSplat(
sceneData.cameraData.projection,
sceneData.cameraData.view,
visibleGaussianSplat.localToWorld.Transpose(),
visibleGaussianSplat.localToWorld.Inverse().Transpose(),
visibleGaussianSplat.localToWorld.Inverse(),
Math::Vector4(sceneData.cameraData.worldRight, 0.0f),
Math::Vector4(sceneData.cameraData.worldUp, 0.0f),
Math::Vector4(sceneData.cameraData.worldPosition, sceneData.cameraData.nearClipPlane),
Math::Vector4(sceneData.cameraData.worldPosition, 0.0f),
Math::Vector4(
static_cast<float>(sceneData.cameraData.viewportWidth),
static_cast<float>(sceneData.cameraData.viewportHeight),