/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/RendererCore/Pipeline/Implementation/Passes/SourcePass.cpp
275 строк
9 KB
Sanakan8472
Render Graph (#1948)
03 июн 2026, 10:19
Не верифицирован
03 июн 2026, 10:19
60bb12c
Код
Авторство
О чём код?
#include <RendererCore/RendererCorePCH.h> #include <Core/Graphics/Camera.h> #include <Foundation/IO/TypeVersionContext.h> #include <RendererCore/Pipeline/Passes/SourcePass.h> #include <RendererCore/Pipeline/View.h> #include <RendererCore/RenderContext/RenderContext.h> #include <RendererFoundation/Resources/Texture.h> // clang-format off EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezSourcePass, 3, ezRTTIDefaultAllocator<ezSourcePass>) { EZ_BEGIN_PROPERTIES { EZ_MEMBER_PROPERTY("Output", m_PinOutput), EZ_ENUM_MEMBER_PROPERTY("Format", ezSourceFormat, m_Format), EZ_ENUM_MEMBER_PROPERTY("MSAA_Mode", ezGALMSAASampleCount, m_MsaaMode), EZ_MEMBER_PROPERTY("ClearColor", m_ClearColor)->AddAttributes(new ezExposeColorAlphaAttribute()), EZ_MEMBER_PROPERTY("Clear", m_bClear), } EZ_END_PROPERTIES; EZ_BEGIN_ATTRIBUTES { new ezCategoryAttribute("Input") } EZ_END_ATTRIBUTES; } EZ_END_DYNAMIC_REFLECTED_TYPE; EZ_BEGIN_STATIC_REFLECTED_ENUM(ezSourceFormat, 1) EZ_ENUM_CONSTANTS( ezSourceFormat::Color4Channel8BitNormalized_sRGB, ezSourceFormat::Color4Channel8BitNormalized, ezSourceFormat::Color4Channel16BitFloat, ezSourceFormat::Color4Channel32BitFloat, ezSourceFormat::Color3Channel11_11_10BitFloat, ezSourceFormat::Depth16Bit, ezSourceFormat::Depth24BitStencil8Bit, ezSourceFormat::Depth32BitFloat ) EZ_END_STATIC_REFLECTED_ENUM; // clang-format on ezSourcePass::ezSourcePass(const char* szName) : ezRenderPipelinePass(szName, true) { } ezSourcePass::~ezSourcePass() = default; ezGALTextureCreationDescription ezSourcePass::GetOutputDescription(const ezViewData& viewData, const ezCamera& camera, ezEnum<ezSourceFormat> format, ezEnum<ezGALMSAASampleCount> msaaMode) { ezUInt32 uiWidth = static_cast<ezUInt32>(viewData.m_ViewPortRect.width); ezUInt32 uiHeight = static_cast<ezUInt32>(viewData.m_ViewPortRect.height); ezGALDevice* pDevice = ezGALDevice::GetDefaultDevice(); const ezGALRenderTargets& renderTargets = viewData.GetActiveRenderTargets(); ezGALTextureCreationDescription desc; desc.m_Type = ezGALTextureType::Texture2DArray; // Color if (format == ezSourceFormat::Color4Channel8BitNormalized || format == ezSourceFormat::Color4Channel8BitNormalized_sRGB) { ezGALResourceFormat::Enum preferredFormat = ezGALResourceFormat::Invalid; if (const ezGALTexture* pTexture = pDevice->GetTexture(renderTargets.m_hRTs[0])) { auto rendertargetDesc = pTexture->GetDescription(); preferredFormat = rendertargetDesc.m_Format; } switch (preferredFormat) { case ezGALResourceFormat::RGBAUByteNormalized: case ezGALResourceFormat::RGBAUByteNormalizedsRGB: default: if (format == ezSourceFormat::Color4Channel8BitNormalized_sRGB) { desc.m_Format = ezGALResourceFormat::RGBAUByteNormalizedsRGB; } else { desc.m_Format = ezGALResourceFormat::RGBAUByteNormalized; } break; case ezGALResourceFormat::BGRAUByteNormalized: case ezGALResourceFormat::BGRAUByteNormalizedsRGB: if (format == ezSourceFormat::Color4Channel8BitNormalized_sRGB) { desc.m_Format = ezGALResourceFormat::BGRAUByteNormalizedsRGB; } else { desc.m_Format = ezGALResourceFormat::BGRAUByteNormalized; } break; } } else { switch (format) { case ezSourceFormat::Color4Channel16BitFloat: desc.m_Format = ezGALResourceFormat::RGBAHalf; break; case ezSourceFormat::Color4Channel32BitFloat: desc.m_Format = ezGALResourceFormat::RGBAFloat; break; case ezSourceFormat::Color3Channel11_11_10BitFloat: { const ezGALDeviceCapabilities& caps = ezGALDevice::GetDefaultDevice()->GetCapabilities(); const bool bSupportsRG11B10Float = caps.m_FormatSupport[ezGALResourceFormat::RG11B10Float].AreAllSet(ezGALResourceFormatSupport::RenderTarget | ezGALResourceFormatSupport::Texture); desc.m_Format = bSupportsRG11B10Float ? ezGALResourceFormat::RG11B10Float : ezGALResourceFormat::RGBAHalf; break; } case ezSourceFormat::Depth16Bit: desc.m_Format = ezGALResourceFormat::D16; break; case ezSourceFormat::Depth24BitStencil8Bit: desc.m_Format = ezGALResourceFormat::D24S8; break; case ezSourceFormat::Depth32BitFloat: desc.m_Format = ezGALResourceFormat::DFloat; break; default: EZ_ASSERT_NOT_IMPLEMENTED } } desc.m_uiWidth = uiWidth; desc.m_uiHeight = uiHeight; desc.m_SampleCount = msaaMode; desc.m_TextureFlags.Add(ezGALTextureUsageFlags::RenderTarget); desc.m_uiArraySize = camera.IsStereoscopic() ? 2 : 1; return desc; } ezStatus ezSourcePass::AddRenderPasses(const ezViewData& viewData, const ezCamera& camera, ezRenderGraph& ref_graph, const ezArrayPtr<const ezRenderPipelinePinConnection> inputs, ezArrayPtr<ezRenderPipelinePinConnection> outputs) { auto desc = GetOutputDescription(viewData, camera, m_Format, m_MsaaMode); ezRenderGraphTextureHandle hOutput = ref_graph.CreateTexture(desc); outputs[m_PinOutput.m_uiOutputIndex].m_TextureHandle = hOutput; if (m_bClear) { if (ezGALResourceFormat::IsDepthFormat(desc.m_Format)) { auto pass = ref_graph.AddGraphicsPass("ClearDepth"); pass.AddDepthStencilTarget(hOutput, {}, ezGALRenderTargetLoadOp::Clear, {}, ezGALRenderTargetLoadOp::Clear); pass.SetClearDepth(); pass.SetClearStencil(); } else { auto pass = ref_graph.AddGraphicsPass("ClearColor"); pass.AddColorTarget(hOutput, {}, ezGALRenderTargetLoadOp::Clear); pass.SetClearColor(0, m_ClearColor); } } return EZ_SUCCESS; } ezResult ezSourcePass::Serialize(ezStreamWriter& inout_stream) const { EZ_SUCCEED_OR_RETURN(SUPER::Serialize(inout_stream)); inout_stream << m_Format; inout_stream << m_MsaaMode; inout_stream << m_ClearColor; inout_stream << m_bClear; return EZ_SUCCESS; } ezResult ezSourcePass::Deserialize(ezStreamReader& inout_stream) { EZ_SUCCEED_OR_RETURN(SUPER::Deserialize(inout_stream)); const ezUInt32 uiVersion = ezTypeVersionReadContext::GetContext()->GetTypeVersion(GetStaticRTTI()); EZ_IGNORE_UNUSED(uiVersion); inout_stream >> m_Format; inout_stream >> m_MsaaMode; inout_stream >> m_ClearColor; inout_stream >> m_bClear; return EZ_SUCCESS; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// #include <Foundation/Reflection/ReflectionUtils.h> #include <Foundation/Serialization/AbstractObjectGraph.h> #include <Foundation/Serialization/GraphPatch.h> class ezSourcePassPatch_1_2 : public ezGraphPatch { public: ezSourcePassPatch_1_2() : ezGraphPatch("ezSourcePass", 2) { } virtual void Patch(ezGraphPatchContext& ref_context, ezAbstractObjectGraph* pGraph, ezAbstractObjectNode* pNode) const override { pNode->RenameProperty("MSAA Mode", "MSAA_Mode"); pNode->RenameProperty("Clear Color", "ClearColor"); } }; ezSourcePassPatch_1_2 g_ezSourcePassPatch_1_2; class ezSourcePassPatch_2_3 : public ezGraphPatch { public: ezSourcePassPatch_2_3() : ezGraphPatch("ezSourcePass", 3) { } virtual void Patch(ezGraphPatchContext& ref_context, ezAbstractObjectGraph* pGraph, ezAbstractObjectNode* pNode) const override { ezAbstractObjectNode::Property* formatProperty = pNode->FindProperty("Format"); if (formatProperty == nullptr) return; auto formatName = formatProperty->m_Value.Get<ezString>(); ezEnum<ezGALResourceFormat> oldFormat; ezReflectionUtils::StringToEnumeration<ezGALResourceFormat>(formatName.GetData(), oldFormat); ezEnum<ezSourceFormat> newFormat; switch (oldFormat) { case ezGALResourceFormat::RGBAHalf: newFormat = ezSourceFormat::Color4Channel16BitFloat; break; case ezGALResourceFormat::RGBAFloat: newFormat = ezSourceFormat::Color4Channel32BitFloat; break; case ezGALResourceFormat::RG11B10Float: newFormat = ezSourceFormat::Color3Channel11_11_10BitFloat; break; case ezGALResourceFormat::D16: newFormat = ezSourceFormat::Depth16Bit; break; case ezGALResourceFormat::D24S8: newFormat = ezSourceFormat::Depth24BitStencil8Bit; break; case ezGALResourceFormat::DFloat: newFormat = ezSourceFormat::Depth32BitFloat; break; case ezGALResourceFormat::RGBAUByteNormalized: case ezGALResourceFormat::BGRAUByteNormalized: newFormat = ezSourceFormat::Color4Channel8BitNormalized; break; case ezGALResourceFormat::RGBAUByteNormalizedsRGB: case ezGALResourceFormat::BGRAUByteNormalizedsRGB: newFormat = ezSourceFormat::Color4Channel8BitNormalized_sRGB; break; default: newFormat = ezSourceFormat::Default; break; } ezStringBuilder newFormatName; ezReflectionUtils::EnumerationToString(newFormat, newFormatName); formatProperty->m_Value = newFormatName.GetView(); } }; ezSourcePassPatch_2_3 g_ezSourcePassPatch_2_3; EZ_STATICLINK_FILE(RendererCore, RendererCore_Pipeline_Implementation_Passes_SourcePass);