2026-04-18 16:08:01 +08:00
|
|
|
#include "Rendering/Passes/BuiltinVectorFullscreenPass.h"
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
#include "Core/Asset/ResourceManager.h"
|
|
|
|
|
#include "Debug/Logger.h"
|
2026-04-22 00:43:25 +08:00
|
|
|
#include "Rendering/Builtin/BuiltinPassLayoutUtils.h"
|
2026-04-11 22:14:02 +08:00
|
|
|
#include "Rendering/Internal/RenderSurfacePipelineUtils.h"
|
|
|
|
|
#include "Rendering/Internal/ShaderVariantUtils.h"
|
2026-04-06 13:30:53 +08:00
|
|
|
#include "Rendering/RenderSurface.h"
|
2026-04-22 00:43:25 +08:00
|
|
|
#include <XCEngine/Rendering/RenderPassGraphContract.h>
|
2026-04-06 13:30:53 +08:00
|
|
|
#include "Resources/BuiltinResources.h"
|
|
|
|
|
#include "RHI/RHICommandList.h"
|
|
|
|
|
#include "RHI/RHIDescriptorPool.h"
|
|
|
|
|
#include "RHI/RHIDescriptorSet.h"
|
|
|
|
|
#include "RHI/RHIDevice.h"
|
|
|
|
|
#include "RHI/RHIPipelineLayout.h"
|
|
|
|
|
#include "RHI/RHIPipelineState.h"
|
|
|
|
|
#include "RHI/RHIResourceView.h"
|
|
|
|
|
#include "RHI/RHISampler.h"
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
#include <algorithm>
|
2026-04-06 13:30:53 +08:00
|
|
|
#include <utility>
|
2026-04-22 00:43:25 +08:00
|
|
|
#include <vector>
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace Rendering {
|
|
|
|
|
namespace Passes {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct PostProcessConstants {
|
2026-04-18 16:08:01 +08:00
|
|
|
Math::Vector4 vectorPayload = Math::Vector4::One();
|
2026-04-06 13:30:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Resources::ShaderPass* FindCompatiblePass(
|
|
|
|
|
const Resources::Shader& shader,
|
2026-04-18 16:08:01 +08:00
|
|
|
Resources::ShaderBackend backend,
|
|
|
|
|
const Containers::String& preferredPassName) {
|
|
|
|
|
if (!preferredPassName.Empty()) {
|
|
|
|
|
const Resources::ShaderPass* preferredPass =
|
|
|
|
|
shader.FindPass(preferredPassName);
|
|
|
|
|
if (preferredPass != nullptr &&
|
|
|
|
|
::XCEngine::Rendering::Internal::ShaderPassHasGraphicsVariants(
|
|
|
|
|
shader,
|
|
|
|
|
preferredPass->name,
|
|
|
|
|
backend)) {
|
|
|
|
|
return preferredPass;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
const Resources::ShaderPass* colorScalePass =
|
|
|
|
|
shader.FindPass("ColorScale");
|
2026-04-06 13:30:53 +08:00
|
|
|
if (colorScalePass != nullptr &&
|
2026-04-18 16:08:01 +08:00
|
|
|
::XCEngine::Rendering::Internal::ShaderPassHasGraphicsVariants(
|
|
|
|
|
shader,
|
|
|
|
|
colorScalePass->name,
|
|
|
|
|
backend)) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return colorScalePass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shader.GetPassCount() > 0 &&
|
2026-04-22 00:43:25 +08:00
|
|
|
::XCEngine::Rendering::Internal::ShaderPassHasGraphicsVariants(
|
|
|
|
|
shader,
|
|
|
|
|
shader.GetPasses()[0].name,
|
|
|
|
|
backend)) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return &shader.GetPasses()[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
bool UsesContiguousDescriptorSets(
|
|
|
|
|
const BuiltinPassResourceBindingPlan& bindingPlan) {
|
|
|
|
|
if (bindingPlan.bindings.Empty()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<bool> usedSets(
|
|
|
|
|
static_cast<size_t>(bindingPlan.maxSetIndex) + 1u,
|
|
|
|
|
false);
|
|
|
|
|
Core::uint32 minSet = UINT32_MAX;
|
|
|
|
|
Core::uint32 maxSet = 0u;
|
|
|
|
|
for (const BuiltinPassResourceBindingDesc& binding :
|
|
|
|
|
bindingPlan.bindings) {
|
|
|
|
|
usedSets[binding.location.set] = true;
|
|
|
|
|
minSet = std::min(minSet, binding.location.set);
|
|
|
|
|
maxSet = std::max(maxSet, binding.location.set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Core::uint32 setIndex = minSet;
|
|
|
|
|
setIndex <= maxSet;
|
|
|
|
|
++setIndex) {
|
|
|
|
|
if (!usedSets[setIndex]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsSupportedFullscreenBindingPlan(
|
|
|
|
|
const BuiltinPassResourceBindingPlan& bindingPlan) {
|
|
|
|
|
if (!UsesContiguousDescriptorSets(bindingPlan)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const BuiltinPassResourceBindingDesc& binding :
|
|
|
|
|
bindingPlan.bindings) {
|
|
|
|
|
switch (binding.semantic) {
|
|
|
|
|
case BuiltinPassResourceSemantic::PassConstants:
|
|
|
|
|
case BuiltinPassResourceSemantic::SourceColorTexture:
|
|
|
|
|
case BuiltinPassResourceSemantic::MaterialTexture:
|
|
|
|
|
case BuiltinPassResourceSemantic::LinearClampSampler:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RenderPassContext::TextureBindingView* FindTextureBindingView(
|
|
|
|
|
const RenderPassContext& context,
|
|
|
|
|
const BuiltinPassResourceBindingDesc& bindingDesc) {
|
|
|
|
|
auto matchesName =
|
|
|
|
|
[&bindingDesc](
|
|
|
|
|
const RenderPassContext::TextureBindingView& bindingView) {
|
|
|
|
|
return bindingView.resourceName ==
|
|
|
|
|
bindingDesc.name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto it =
|
|
|
|
|
std::find_if(
|
|
|
|
|
context.textureBindings.begin(),
|
|
|
|
|
context.textureBindings.end(),
|
|
|
|
|
matchesName);
|
|
|
|
|
return it != context.textureBindings.end()
|
|
|
|
|
? &(*it)
|
|
|
|
|
: nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 13:30:53 +08:00
|
|
|
RHI::GraphicsPipelineDesc CreatePipelineDesc(
|
|
|
|
|
RHI::RHIType backendType,
|
|
|
|
|
RHI::RHIPipelineLayout* pipelineLayout,
|
|
|
|
|
const Resources::Shader& shader,
|
|
|
|
|
const Containers::String& passName,
|
2026-04-11 22:14:02 +08:00
|
|
|
const RenderSurface& surface) {
|
2026-04-06 13:30:53 +08:00
|
|
|
RHI::GraphicsPipelineDesc pipelineDesc = {};
|
|
|
|
|
pipelineDesc.pipelineLayout = pipelineLayout;
|
2026-04-22 00:43:25 +08:00
|
|
|
pipelineDesc.topologyType = static_cast<uint32_t>(
|
|
|
|
|
RHI::PrimitiveTopologyType::Triangle);
|
|
|
|
|
::XCEngine::Rendering::Internal::
|
|
|
|
|
ApplySingleColorAttachmentPropertiesToGraphicsPipelineDesc(
|
|
|
|
|
surface,
|
|
|
|
|
pipelineDesc);
|
|
|
|
|
pipelineDesc.depthStencilFormat = static_cast<uint32_t>(
|
|
|
|
|
RHI::Format::Unknown);
|
|
|
|
|
|
|
|
|
|
pipelineDesc.rasterizerState.fillMode = static_cast<uint32_t>(
|
|
|
|
|
RHI::FillMode::Solid);
|
|
|
|
|
pipelineDesc.rasterizerState.cullMode = static_cast<uint32_t>(
|
|
|
|
|
RHI::CullMode::None);
|
|
|
|
|
pipelineDesc.rasterizerState.frontFace =
|
|
|
|
|
static_cast<uint32_t>(RHI::FrontFace::CounterClockwise);
|
2026-04-06 13:30:53 +08:00
|
|
|
pipelineDesc.rasterizerState.depthClipEnable = true;
|
|
|
|
|
|
|
|
|
|
pipelineDesc.blendState.blendEnable = false;
|
2026-04-22 00:43:25 +08:00
|
|
|
pipelineDesc.blendState.srcBlend = static_cast<uint32_t>(
|
|
|
|
|
RHI::BlendFactor::One);
|
|
|
|
|
pipelineDesc.blendState.dstBlend = static_cast<uint32_t>(
|
|
|
|
|
RHI::BlendFactor::Zero);
|
|
|
|
|
pipelineDesc.blendState.srcBlendAlpha =
|
|
|
|
|
static_cast<uint32_t>(RHI::BlendFactor::One);
|
|
|
|
|
pipelineDesc.blendState.dstBlendAlpha =
|
|
|
|
|
static_cast<uint32_t>(RHI::BlendFactor::Zero);
|
|
|
|
|
pipelineDesc.blendState.blendOp = static_cast<uint32_t>(
|
|
|
|
|
RHI::BlendOp::Add);
|
|
|
|
|
pipelineDesc.blendState.blendOpAlpha = static_cast<uint32_t>(
|
|
|
|
|
RHI::BlendOp::Add);
|
|
|
|
|
pipelineDesc.blendState.colorWriteMask =
|
|
|
|
|
static_cast<uint8_t>(RHI::ColorWriteMask::All);
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
pipelineDesc.depthStencilState.depthTestEnable = false;
|
|
|
|
|
pipelineDesc.depthStencilState.depthWriteEnable = false;
|
2026-04-22 00:43:25 +08:00
|
|
|
pipelineDesc.depthStencilState.depthFunc = static_cast<uint32_t>(
|
|
|
|
|
RHI::ComparisonFunc::Always);
|
|
|
|
|
|
|
|
|
|
const Resources::ShaderPass* shaderPass =
|
|
|
|
|
shader.FindPass(passName);
|
|
|
|
|
const Resources::ShaderBackend backend =
|
|
|
|
|
::XCEngine::Rendering::Internal::ToShaderBackend(
|
|
|
|
|
backendType);
|
2026-04-06 13:30:53 +08:00
|
|
|
if (const Resources::ShaderStageVariant* vertexVariant =
|
2026-04-22 00:43:25 +08:00
|
|
|
shader.FindVariant(
|
|
|
|
|
passName,
|
|
|
|
|
Resources::ShaderType::Vertex,
|
|
|
|
|
backend)) {
|
2026-04-08 16:09:15 +08:00
|
|
|
if (shaderPass != nullptr) {
|
2026-04-11 22:14:02 +08:00
|
|
|
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
|
2026-04-09 02:59:36 +08:00
|
|
|
shader.GetPath(),
|
2026-04-08 16:09:15 +08:00
|
|
|
*shaderPass,
|
|
|
|
|
backend,
|
|
|
|
|
*vertexVariant,
|
|
|
|
|
pipelineDesc.vertexShader);
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
if (const Resources::ShaderStageVariant* fragmentVariant =
|
2026-04-22 00:43:25 +08:00
|
|
|
shader.FindVariant(
|
|
|
|
|
passName,
|
|
|
|
|
Resources::ShaderType::Fragment,
|
|
|
|
|
backend)) {
|
2026-04-08 16:09:15 +08:00
|
|
|
if (shaderPass != nullptr) {
|
2026-04-11 22:14:02 +08:00
|
|
|
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
|
2026-04-09 02:59:36 +08:00
|
|
|
shader.GetPath(),
|
2026-04-08 16:09:15 +08:00
|
|
|
*shaderPass,
|
|
|
|
|
backend,
|
|
|
|
|
*fragmentVariant,
|
|
|
|
|
pipelineDesc.fragmentShader);
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pipelineDesc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
BuiltinVectorFullscreenPass::BuiltinVectorFullscreenPass(
|
|
|
|
|
const Math::Vector4& vectorPayload,
|
|
|
|
|
Containers::String shaderPath,
|
|
|
|
|
Containers::String preferredPassName)
|
2026-04-06 13:30:53 +08:00
|
|
|
: m_shaderPath(std::move(shaderPath))
|
2026-04-18 16:08:01 +08:00
|
|
|
, m_preferredPassName(std::move(preferredPassName))
|
|
|
|
|
, m_vectorPayload(vectorPayload) {
|
2026-04-06 13:30:53 +08:00
|
|
|
if (m_shaderPath.Empty()) {
|
2026-04-22 00:43:25 +08:00
|
|
|
m_shaderPath =
|
|
|
|
|
Resources::GetBuiltinColorScalePostProcessShaderPath();
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
BuiltinVectorFullscreenPass::~BuiltinVectorFullscreenPass() {
|
2026-04-06 13:30:53 +08:00
|
|
|
Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
const char* BuiltinVectorFullscreenPass::GetName() const {
|
|
|
|
|
return "BuiltinVectorFullscreenPass";
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
bool BuiltinVectorFullscreenPass::SupportsRenderGraph() const {
|
2026-04-14 17:16:08 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
bool BuiltinVectorFullscreenPass::RecordRenderGraph(
|
2026-04-14 17:16:08 +08:00
|
|
|
const RenderPassRenderGraphContext& context) {
|
2026-04-15 12:52:44 +08:00
|
|
|
return RecordSourceColorFullscreenRasterPass(
|
2026-04-14 17:16:08 +08:00
|
|
|
*this,
|
2026-04-15 12:52:44 +08:00
|
|
|
context);
|
2026-04-14 17:16:08 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
bool BuiltinVectorFullscreenPass::Execute(
|
|
|
|
|
const RenderPassContext& context) {
|
2026-04-11 22:14:02 +08:00
|
|
|
if (!context.renderContext.IsValid() ||
|
2026-04-22 00:43:25 +08:00
|
|
|
!::XCEngine::Rendering::Internal::HasSingleColorAttachment(
|
|
|
|
|
context.surface)) {
|
2026-04-11 22:14:02 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-22 00:43:25 +08:00
|
|
|
|
|
|
|
|
const std::vector<RHI::RHIResourceView*>& colorAttachments =
|
|
|
|
|
context.surface.GetColorAttachments();
|
|
|
|
|
if (colorAttachments.empty() ||
|
|
|
|
|
colorAttachments[0] == nullptr) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
const Math::RectInt renderArea =
|
|
|
|
|
context.surface.GetRenderArea();
|
|
|
|
|
if (renderArea.width <= 0 ||
|
|
|
|
|
renderArea.height <= 0) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (!EnsureInitialized(
|
|
|
|
|
context.renderContext,
|
|
|
|
|
context.surface)) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (m_passLayout.sourceColorTexture.IsValid() &&
|
|
|
|
|
(context.sourceSurface == nullptr ||
|
|
|
|
|
context.sourceColorView == nullptr)) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (!UpdateDescriptorSets(context)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
RHI::RHICommandList* commandList =
|
|
|
|
|
context.renderContext.commandList;
|
|
|
|
|
if (commandList == nullptr) {
|
|
|
|
|
return false;
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
RHI::RHIResourceView* renderTarget =
|
|
|
|
|
colorAttachments[0];
|
|
|
|
|
const bool autoTransitionSource =
|
|
|
|
|
m_passLayout.sourceColorTexture.IsValid() &&
|
|
|
|
|
context.sourceSurface != nullptr &&
|
|
|
|
|
context.sourceSurface->IsAutoTransitionEnabled();
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
if (context.surface.IsAutoTransitionEnabled()) {
|
|
|
|
|
commandList->TransitionBarrier(
|
|
|
|
|
renderTarget,
|
|
|
|
|
context.surface.GetColorStateBefore(),
|
|
|
|
|
RHI::ResourceStates::RenderTarget);
|
|
|
|
|
}
|
2026-04-22 00:43:25 +08:00
|
|
|
if (m_passLayout.sourceColorTexture.IsValid()) {
|
|
|
|
|
if (autoTransitionSource) {
|
|
|
|
|
commandList->TransitionBarrier(
|
|
|
|
|
context.sourceColorView,
|
|
|
|
|
context.sourceColorState,
|
|
|
|
|
RHI::ResourceStates::PixelShaderResource);
|
|
|
|
|
} else if (context.sourceColorState !=
|
|
|
|
|
RHI::ResourceStates::PixelShaderResource) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-11 22:14:02 +08:00
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
commandList->SetRenderTargets(1, &renderTarget, nullptr);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
commandList->SetViewport(viewport);
|
|
|
|
|
commandList->SetScissorRect(scissorRect);
|
2026-04-22 00:43:25 +08:00
|
|
|
commandList->SetPrimitiveTopology(
|
|
|
|
|
RHI::PrimitiveTopology::TriangleList);
|
2026-04-06 13:30:53 +08:00
|
|
|
commandList->SetPipelineState(m_pipelineState);
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (m_passLayout.descriptorSetCount > 0u) {
|
|
|
|
|
std::vector<RHI::RHIDescriptorSet*> descriptorSets(
|
|
|
|
|
m_passLayout.descriptorSetCount,
|
|
|
|
|
nullptr);
|
|
|
|
|
for (Core::uint32 descriptorOffset = 0u;
|
|
|
|
|
descriptorOffset < m_passLayout.descriptorSetCount;
|
|
|
|
|
++descriptorOffset) {
|
|
|
|
|
const Core::uint32 setIndex =
|
|
|
|
|
m_passLayout.firstDescriptorSet +
|
|
|
|
|
descriptorOffset;
|
|
|
|
|
if (setIndex >=
|
|
|
|
|
m_passLayout.descriptorSets.size() ||
|
|
|
|
|
m_passLayout.descriptorSets[setIndex].set ==
|
|
|
|
|
nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
descriptorSets[descriptorOffset] =
|
|
|
|
|
m_passLayout.descriptorSets[setIndex].set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commandList->SetGraphicsDescriptorSets(
|
|
|
|
|
m_passLayout.firstDescriptorSet,
|
|
|
|
|
m_passLayout.descriptorSetCount,
|
|
|
|
|
descriptorSets.data(),
|
|
|
|
|
m_passLayout.pipelineLayout);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 13:30:53 +08:00
|
|
|
commandList->Draw(3, 1, 0, 0);
|
|
|
|
|
commandList->EndRenderPass();
|
|
|
|
|
|
|
|
|
|
if (context.surface.IsAutoTransitionEnabled()) {
|
|
|
|
|
commandList->TransitionBarrier(
|
|
|
|
|
renderTarget,
|
|
|
|
|
RHI::ResourceStates::RenderTarget,
|
|
|
|
|
context.surface.GetColorStateAfter());
|
|
|
|
|
}
|
2026-04-22 00:43:25 +08:00
|
|
|
if (m_passLayout.sourceColorTexture.IsValid() &&
|
|
|
|
|
autoTransitionSource) {
|
2026-04-11 22:14:02 +08:00
|
|
|
commandList->TransitionBarrier(
|
|
|
|
|
context.sourceColorView,
|
|
|
|
|
RHI::ResourceStates::PixelShaderResource,
|
|
|
|
|
context.sourceColorState);
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
void BuiltinVectorFullscreenPass::Shutdown() {
|
2026-04-06 13:30:53 +08:00
|
|
|
DestroyResources();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
void BuiltinVectorFullscreenPass::SetVectorPayload(
|
|
|
|
|
const Math::Vector4& vectorPayload) {
|
2026-04-18 16:08:01 +08:00
|
|
|
m_vectorPayload = vectorPayload;
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
const Math::Vector4& BuiltinVectorFullscreenPass::GetVectorPayload() const {
|
|
|
|
|
return m_vectorPayload;
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
void BuiltinVectorFullscreenPass::SetShaderPath(
|
|
|
|
|
const Containers::String& shaderPath) {
|
2026-04-06 13:30:53 +08:00
|
|
|
if (m_shaderPath == shaderPath) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestroyResources();
|
|
|
|
|
m_shaderPath = shaderPath;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
const Containers::String& BuiltinVectorFullscreenPass::GetShaderPath() const {
|
2026-04-06 13:30:53 +08:00
|
|
|
return m_shaderPath;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
void BuiltinVectorFullscreenPass::SetPreferredPassName(
|
|
|
|
|
const Containers::String& preferredPassName) {
|
|
|
|
|
if (m_preferredPassName == preferredPassName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestroyResources();
|
|
|
|
|
m_preferredPassName = preferredPassName;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
const Containers::String&
|
|
|
|
|
BuiltinVectorFullscreenPass::GetPreferredPassName() const {
|
2026-04-18 16:08:01 +08:00
|
|
|
return m_preferredPassName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BuiltinVectorFullscreenPass::EnsureInitialized(
|
2026-04-06 13:30:53 +08:00
|
|
|
const RenderContext& renderContext,
|
2026-04-11 22:14:02 +08:00
|
|
|
const RenderSurface& surface) {
|
|
|
|
|
const RHI::Format renderTargetFormat =
|
2026-04-22 00:43:25 +08:00
|
|
|
::XCEngine::Rendering::Internal::ResolveSurfaceColorFormat(
|
|
|
|
|
surface,
|
|
|
|
|
0u);
|
2026-04-11 22:14:02 +08:00
|
|
|
const uint32_t renderTargetSampleCount =
|
2026-04-22 00:43:25 +08:00
|
|
|
::XCEngine::Rendering::Internal::ResolveSurfaceSampleCount(
|
|
|
|
|
surface);
|
2026-04-11 22:14:02 +08:00
|
|
|
const uint32_t renderTargetSampleQuality =
|
2026-04-22 00:43:25 +08:00
|
|
|
::XCEngine::Rendering::Internal::ResolveSurfaceSampleQuality(
|
|
|
|
|
surface);
|
2026-04-06 13:30:53 +08:00
|
|
|
if (m_device == renderContext.device &&
|
|
|
|
|
m_backendType == renderContext.backendType &&
|
|
|
|
|
m_renderTargetFormat == renderTargetFormat &&
|
2026-04-22 00:43:25 +08:00
|
|
|
m_renderTargetSampleCount ==
|
|
|
|
|
renderTargetSampleCount &&
|
|
|
|
|
m_renderTargetSampleQuality ==
|
|
|
|
|
renderTargetSampleQuality &&
|
|
|
|
|
m_passLayout.pipelineLayout != nullptr &&
|
2026-04-06 13:30:53 +08:00
|
|
|
m_pipelineState != nullptr &&
|
2026-04-22 00:43:25 +08:00
|
|
|
m_sampler != nullptr) {
|
2026-04-06 13:30:53 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestroyResources();
|
2026-04-11 22:14:02 +08:00
|
|
|
return CreateResources(renderContext, surface);
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 16:08:01 +08:00
|
|
|
bool BuiltinVectorFullscreenPass::CreateResources(
|
2026-04-06 13:30:53 +08:00
|
|
|
const RenderContext& renderContext,
|
2026-04-11 22:14:02 +08:00
|
|
|
const RenderSurface& surface) {
|
2026-04-06 13:30:53 +08:00
|
|
|
if (!renderContext.IsValid()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 22:14:02 +08:00
|
|
|
RHI::Format renderTargetFormat = RHI::Format::Unknown;
|
2026-04-22 00:43:25 +08:00
|
|
|
if (!::XCEngine::Rendering::Internal::
|
|
|
|
|
TryResolveSingleColorAttachmentFormat(
|
|
|
|
|
surface,
|
|
|
|
|
renderTargetFormat)) {
|
2026-04-11 22:14:02 +08:00
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
2026-04-22 00:43:25 +08:00
|
|
|
"BuiltinVectorFullscreenPass requires exactly one "
|
|
|
|
|
"valid destination color attachment");
|
2026-04-11 22:14:02 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 13:30:53 +08:00
|
|
|
if (m_shaderPath.Empty()) {
|
|
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
2026-04-22 00:43:25 +08:00
|
|
|
"BuiltinVectorFullscreenPass requires a shader path "
|
|
|
|
|
"before resource creation");
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
m_shader =
|
|
|
|
|
Resources::ResourceManager::Get().Load<Resources::Shader>(
|
|
|
|
|
m_shaderPath);
|
2026-04-06 13:30:53 +08:00
|
|
|
if (!m_shader.IsValid()) {
|
|
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
2026-04-22 00:43:25 +08:00
|
|
|
"BuiltinVectorFullscreenPass failed to load "
|
|
|
|
|
"configured fullscreen shader resource");
|
2026-04-06 13:30:53 +08:00
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
const Resources::ShaderBackend backend =
|
|
|
|
|
::XCEngine::Rendering::Internal::ToShaderBackend(
|
|
|
|
|
renderContext.backendType);
|
2026-04-18 16:08:01 +08:00
|
|
|
const Resources::ShaderPass* selectedPass =
|
2026-04-22 00:43:25 +08:00
|
|
|
FindCompatiblePass(
|
|
|
|
|
*m_shader.Get(),
|
|
|
|
|
backend,
|
|
|
|
|
m_preferredPassName);
|
2026-04-18 16:08:01 +08:00
|
|
|
if (selectedPass == nullptr) {
|
2026-04-06 13:30:53 +08:00
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
2026-04-18 16:08:01 +08:00
|
|
|
m_preferredPassName.Empty()
|
2026-04-22 00:43:25 +08:00
|
|
|
? "BuiltinVectorFullscreenPass could not resolve "
|
|
|
|
|
"a compatible fullscreen shader pass"
|
|
|
|
|
: "BuiltinVectorFullscreenPass could not resolve "
|
|
|
|
|
"the configured fullscreen shader pass");
|
|
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuiltinPassResourceBindingPlan bindingPlan = {};
|
|
|
|
|
Containers::String bindingPlanError;
|
|
|
|
|
if (!TryBuildBuiltinPassResourceBindingPlan(
|
|
|
|
|
*selectedPass,
|
|
|
|
|
bindingPlan,
|
|
|
|
|
&bindingPlanError)) {
|
|
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
|
|
|
|
(Containers::String(
|
|
|
|
|
"BuiltinVectorFullscreenPass failed to "
|
|
|
|
|
"resolve shader resource bindings: ") +
|
|
|
|
|
bindingPlanError)
|
|
|
|
|
.CStr());
|
|
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsSupportedFullscreenBindingPlan(bindingPlan)) {
|
|
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
|
|
|
|
"BuiltinVectorFullscreenPass only supports "
|
|
|
|
|
"PassConstants, SourceColorTexture, "
|
|
|
|
|
"MaterialTexture, and LinearClampSampler "
|
|
|
|
|
"resource semantics");
|
|
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<BuiltinPassSetLayoutMetadata> setLayouts;
|
|
|
|
|
Containers::String setLayoutError;
|
|
|
|
|
if (!TryBuildBuiltinPassSetLayouts(
|
|
|
|
|
bindingPlan,
|
|
|
|
|
setLayouts,
|
|
|
|
|
&setLayoutError)) {
|
|
|
|
|
Debug::Logger::Get().Error(
|
|
|
|
|
Debug::LogCategory::Rendering,
|
|
|
|
|
(Containers::String(
|
|
|
|
|
"BuiltinVectorFullscreenPass failed to build "
|
|
|
|
|
"descriptor set layouts: ") +
|
|
|
|
|
setLayoutError)
|
|
|
|
|
.CStr());
|
2026-04-06 13:30:53 +08:00
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_device = renderContext.device;
|
|
|
|
|
m_backendType = renderContext.backendType;
|
|
|
|
|
m_renderTargetFormat = renderTargetFormat;
|
2026-04-22 00:43:25 +08:00
|
|
|
m_renderTargetSampleCount =
|
|
|
|
|
::XCEngine::Rendering::Internal::ResolveSurfaceSampleCount(
|
|
|
|
|
surface);
|
|
|
|
|
m_renderTargetSampleQuality =
|
|
|
|
|
::XCEngine::Rendering::Internal::
|
|
|
|
|
ResolveSurfaceSampleQuality(surface);
|
|
|
|
|
|
|
|
|
|
m_passLayout.setLayouts = std::move(setLayouts);
|
|
|
|
|
m_passLayout.descriptorSets.resize(
|
|
|
|
|
m_passLayout.setLayouts.size());
|
|
|
|
|
m_passLayout.boundSetStates.resize(
|
|
|
|
|
m_passLayout.setLayouts.size());
|
|
|
|
|
m_passLayout.passConstants = bindingPlan.passConstants;
|
|
|
|
|
m_passLayout.sourceColorTexture =
|
|
|
|
|
bindingPlan.sourceColorTexture;
|
|
|
|
|
m_passLayout.linearClampSampler =
|
|
|
|
|
bindingPlan.linearClampSampler;
|
|
|
|
|
m_passLayout.firstDescriptorSet =
|
|
|
|
|
bindingPlan.firstDescriptorSet;
|
|
|
|
|
m_passLayout.descriptorSetCount =
|
|
|
|
|
bindingPlan.descriptorSetCount;
|
|
|
|
|
|
|
|
|
|
std::vector<RHI::DescriptorSetLayoutDesc> nativeSetLayouts(
|
|
|
|
|
m_passLayout.setLayouts.size());
|
|
|
|
|
for (size_t setIndex = 0u;
|
|
|
|
|
setIndex < m_passLayout.setLayouts.size();
|
|
|
|
|
++setIndex) {
|
|
|
|
|
nativeSetLayouts[setIndex] =
|
|
|
|
|
m_passLayout.setLayouts[setIndex].layout;
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
RHI::RHIPipelineLayoutDesc pipelineLayoutDesc = {};
|
2026-04-22 00:43:25 +08:00
|
|
|
pipelineLayoutDesc.setLayouts =
|
|
|
|
|
nativeSetLayouts.empty()
|
|
|
|
|
? nullptr
|
|
|
|
|
: nativeSetLayouts.data();
|
|
|
|
|
pipelineLayoutDesc.setLayoutCount =
|
|
|
|
|
static_cast<uint32_t>(nativeSetLayouts.size());
|
|
|
|
|
m_passLayout.pipelineLayout =
|
|
|
|
|
m_device->CreatePipelineLayout(pipelineLayoutDesc);
|
|
|
|
|
if (m_passLayout.pipelineLayout == nullptr) {
|
2026-04-06 13:30:53 +08:00
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHI::SamplerDesc samplerDesc = {};
|
2026-04-22 00:43:25 +08:00
|
|
|
samplerDesc.filter =
|
|
|
|
|
static_cast<uint32_t>(RHI::FilterMode::Linear);
|
|
|
|
|
samplerDesc.addressU = static_cast<uint32_t>(
|
|
|
|
|
RHI::TextureAddressMode::Clamp);
|
|
|
|
|
samplerDesc.addressV = static_cast<uint32_t>(
|
|
|
|
|
RHI::TextureAddressMode::Clamp);
|
|
|
|
|
samplerDesc.addressW = static_cast<uint32_t>(
|
|
|
|
|
RHI::TextureAddressMode::Clamp);
|
2026-04-06 13:30:53 +08:00
|
|
|
samplerDesc.mipLodBias = 0.0f;
|
|
|
|
|
samplerDesc.maxAnisotropy = 1;
|
2026-04-22 00:43:25 +08:00
|
|
|
samplerDesc.comparisonFunc = static_cast<uint32_t>(
|
|
|
|
|
RHI::ComparisonFunc::Always);
|
2026-04-06 13:30:53 +08:00
|
|
|
samplerDesc.minLod = 0.0f;
|
|
|
|
|
samplerDesc.maxLod = 1000.0f;
|
|
|
|
|
m_sampler = m_device->CreateSampler(samplerDesc);
|
|
|
|
|
if (m_sampler == nullptr) {
|
|
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
for (size_t setIndex = 0u;
|
|
|
|
|
setIndex < m_passLayout.setLayouts.size();
|
|
|
|
|
++setIndex) {
|
|
|
|
|
const BuiltinPassSetLayoutMetadata& setLayout =
|
|
|
|
|
m_passLayout.setLayouts[setIndex];
|
|
|
|
|
if (setLayout.bindings.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CreateOwnedDescriptorSet(
|
|
|
|
|
setLayout,
|
|
|
|
|
m_passLayout.descriptorSets[setIndex])) {
|
|
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (setLayout.usesSampler) {
|
|
|
|
|
if (!setLayout.usesLinearClampSampler ||
|
|
|
|
|
!m_passLayout.linearClampSampler.IsValid() ||
|
|
|
|
|
m_passLayout.linearClampSampler.set !=
|
|
|
|
|
setIndex) {
|
|
|
|
|
DestroyResources();
|
2026-04-06 13:30:53 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
m_passLayout.descriptorSets[setIndex]
|
|
|
|
|
.set->UpdateSampler(
|
|
|
|
|
m_passLayout.linearClampSampler.binding,
|
|
|
|
|
m_sampler);
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pipelineState = m_device->CreatePipelineState(
|
|
|
|
|
CreatePipelineDesc(
|
|
|
|
|
m_backendType,
|
2026-04-22 00:43:25 +08:00
|
|
|
m_passLayout.pipelineLayout,
|
2026-04-06 13:30:53 +08:00
|
|
|
*m_shader.Get(),
|
2026-04-18 16:08:01 +08:00
|
|
|
selectedPass->name,
|
2026-04-11 22:14:02 +08:00
|
|
|
surface));
|
2026-04-22 00:43:25 +08:00
|
|
|
if (m_pipelineState == nullptr ||
|
|
|
|
|
!m_pipelineState->IsValid()) {
|
2026-04-06 13:30:53 +08:00
|
|
|
DestroyResources();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
bool BuiltinVectorFullscreenPass::CreateOwnedDescriptorSet(
|
|
|
|
|
const BuiltinPassSetLayoutMetadata& setLayout,
|
|
|
|
|
OwnedDescriptorSet& descriptorSet) {
|
|
|
|
|
RHI::DescriptorPoolDesc poolDesc = {};
|
|
|
|
|
poolDesc.type = setLayout.heapType;
|
|
|
|
|
poolDesc.descriptorCount =
|
|
|
|
|
CountBuiltinPassHeapDescriptors(
|
|
|
|
|
setLayout.heapType,
|
|
|
|
|
setLayout.bindings);
|
|
|
|
|
poolDesc.shaderVisible = setLayout.shaderVisible;
|
|
|
|
|
|
|
|
|
|
descriptorSet.pool =
|
|
|
|
|
m_device->CreateDescriptorPool(poolDesc);
|
|
|
|
|
if (descriptorSet.pool == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
descriptorSet.set =
|
|
|
|
|
descriptorSet.pool->AllocateSet(setLayout.layout);
|
|
|
|
|
if (descriptorSet.set == nullptr) {
|
|
|
|
|
DestroyOwnedDescriptorSet(descriptorSet);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BuiltinVectorFullscreenPass::UpdateDescriptorSets(
|
|
|
|
|
const RenderPassContext& context) {
|
|
|
|
|
for (size_t setIndex = 0u;
|
|
|
|
|
setIndex < m_passLayout.setLayouts.size();
|
|
|
|
|
++setIndex) {
|
|
|
|
|
const BuiltinPassSetLayoutMetadata& setLayout =
|
|
|
|
|
m_passLayout.setLayouts[setIndex];
|
|
|
|
|
if (setLayout.bindings.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OwnedDescriptorSet& descriptorSet =
|
|
|
|
|
m_passLayout.descriptorSets[setIndex];
|
|
|
|
|
BoundSetState& boundSetState =
|
|
|
|
|
m_passLayout.boundSetStates[setIndex];
|
|
|
|
|
if (descriptorSet.set == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-06 13:30:53 +08:00
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
if (setLayout.usesPassConstants) {
|
|
|
|
|
if (!m_passLayout.passConstants.IsValid() ||
|
|
|
|
|
m_passLayout.passConstants.set != setIndex) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PostProcessConstants constants = {
|
|
|
|
|
m_vectorPayload
|
|
|
|
|
};
|
|
|
|
|
descriptorSet.set->WriteConstant(
|
|
|
|
|
m_passLayout.passConstants.binding,
|
|
|
|
|
&constants,
|
|
|
|
|
sizeof(constants));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setLayout.usesSourceColorTexture) {
|
|
|
|
|
if (context.sourceColorView == nullptr ||
|
|
|
|
|
!m_passLayout.sourceColorTexture.IsValid() ||
|
|
|
|
|
m_passLayout.sourceColorTexture.set !=
|
|
|
|
|
setIndex) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boundSetState.sourceColorTextureView !=
|
|
|
|
|
context.sourceColorView) {
|
|
|
|
|
descriptorSet.set->Update(
|
|
|
|
|
m_passLayout.sourceColorTexture.binding,
|
|
|
|
|
context.sourceColorView);
|
|
|
|
|
boundSetState.sourceColorTextureView =
|
|
|
|
|
context.sourceColorView;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setLayout.usesMaterialTextures) {
|
|
|
|
|
if (boundSetState.materialTextureViews.size() !=
|
|
|
|
|
setLayout.materialTextureBindings.size()) {
|
|
|
|
|
boundSetState.materialTextureViews.assign(
|
|
|
|
|
setLayout.materialTextureBindings.size(),
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t bindingIndex = 0u;
|
|
|
|
|
bindingIndex <
|
|
|
|
|
setLayout.materialTextureBindings.size();
|
|
|
|
|
++bindingIndex) {
|
|
|
|
|
const BuiltinPassResourceBindingDesc&
|
|
|
|
|
textureBinding =
|
|
|
|
|
setLayout.materialTextureBindings
|
|
|
|
|
[bindingIndex];
|
|
|
|
|
RHI::RHIResourceView* resolvedTextureView =
|
|
|
|
|
ResolveExtraTextureView(
|
|
|
|
|
context,
|
|
|
|
|
textureBinding);
|
|
|
|
|
if (resolvedTextureView == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boundSetState.materialTextureViews
|
|
|
|
|
[bindingIndex] !=
|
|
|
|
|
resolvedTextureView) {
|
|
|
|
|
descriptorSet.set->Update(
|
|
|
|
|
textureBinding.location.binding,
|
|
|
|
|
resolvedTextureView);
|
|
|
|
|
boundSetState.materialTextureViews
|
|
|
|
|
[bindingIndex] = resolvedTextureView;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (!boundSetState.materialTextureViews
|
|
|
|
|
.empty()) {
|
|
|
|
|
boundSetState.materialTextureViews.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHI::RHIResourceView*
|
|
|
|
|
BuiltinVectorFullscreenPass::ResolveExtraTextureView(
|
|
|
|
|
const RenderPassContext& context,
|
|
|
|
|
const BuiltinPassResourceBindingDesc& bindingDesc) const {
|
|
|
|
|
const RenderPassContext::TextureBindingView* bindingView =
|
|
|
|
|
FindTextureBindingView(
|
|
|
|
|
context,
|
|
|
|
|
bindingDesc);
|
|
|
|
|
return bindingView != nullptr
|
|
|
|
|
? bindingView->resourceView
|
|
|
|
|
: nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuiltinVectorFullscreenPass::DestroyResources() {
|
2026-04-06 13:30:53 +08:00
|
|
|
if (m_pipelineState != nullptr) {
|
|
|
|
|
m_pipelineState->Shutdown();
|
|
|
|
|
delete m_pipelineState;
|
|
|
|
|
m_pipelineState = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
DestroyPassResourceLayout();
|
2026-04-06 13:30:53 +08:00
|
|
|
|
|
|
|
|
if (m_sampler != nullptr) {
|
|
|
|
|
m_sampler->Shutdown();
|
|
|
|
|
delete m_sampler;
|
|
|
|
|
m_sampler = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_shader.Reset();
|
|
|
|
|
m_device = nullptr;
|
|
|
|
|
m_backendType = RHI::RHIType::D3D12;
|
|
|
|
|
m_renderTargetFormat = RHI::Format::Unknown;
|
2026-04-11 22:14:02 +08:00
|
|
|
m_renderTargetSampleCount = 1u;
|
|
|
|
|
m_renderTargetSampleQuality = 0u;
|
2026-04-06 13:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 00:43:25 +08:00
|
|
|
void BuiltinVectorFullscreenPass::DestroyPassResourceLayout() {
|
|
|
|
|
for (OwnedDescriptorSet& descriptorSet :
|
|
|
|
|
m_passLayout.descriptorSets) {
|
|
|
|
|
DestroyOwnedDescriptorSet(descriptorSet);
|
|
|
|
|
}
|
|
|
|
|
m_passLayout.descriptorSets.clear();
|
|
|
|
|
m_passLayout.boundSetStates.clear();
|
|
|
|
|
m_passLayout.setLayouts.clear();
|
|
|
|
|
|
|
|
|
|
if (m_passLayout.pipelineLayout != nullptr) {
|
|
|
|
|
m_passLayout.pipelineLayout->Shutdown();
|
|
|
|
|
delete m_passLayout.pipelineLayout;
|
|
|
|
|
m_passLayout.pipelineLayout = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_passLayout.passConstants = {};
|
|
|
|
|
m_passLayout.sourceColorTexture = {};
|
|
|
|
|
m_passLayout.linearClampSampler = {};
|
|
|
|
|
m_passLayout.firstDescriptorSet = 0u;
|
|
|
|
|
m_passLayout.descriptorSetCount = 0u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuiltinVectorFullscreenPass::DestroyOwnedDescriptorSet(
|
|
|
|
|
OwnedDescriptorSet& descriptorSet) {
|
2026-04-06 13:30:53 +08:00
|
|
|
if (descriptorSet.set != nullptr) {
|
|
|
|
|
descriptorSet.set->Shutdown();
|
|
|
|
|
delete descriptorSet.set;
|
|
|
|
|
descriptorSet.set = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (descriptorSet.pool != nullptr) {
|
|
|
|
|
descriptorSet.pool->Shutdown();
|
|
|
|
|
delete descriptorSet.pool;
|
|
|
|
|
descriptorSet.pool = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Passes
|
|
|
|
|
} // namespace Rendering
|
|
|
|
|
} // namespace XCEngine
|