refactor: unify builtin forward scene execution

This commit is contained in:
2026-04-10 02:56:36 +08:00
parent ff6d6d31fe
commit 57331c1c25
2 changed files with 126 additions and 126 deletions

View File

@@ -36,11 +36,13 @@ namespace Rendering {
class RenderSurface;
namespace Pipelines {
namespace Detail {
class BuiltinForwardOpaquePass;
class BuiltinForwardSkyboxPass;
class BuiltinForwardTransparentPass;
} // namespace Detail
} // namespace Pipelines
namespace Passes {
class BuiltinVolumetricPass;
} // namespace Passes
namespace Pipelines {
class BuiltinForwardPipeline : public RenderPipeline {
public:
@@ -57,10 +59,6 @@ public:
const RenderSceneData& sceneData) override;
private:
friend class Detail::BuiltinForwardOpaquePass;
friend class Detail::BuiltinForwardSkyboxPass;
friend class Detail::BuiltinForwardTransparentPass;
struct OwnedDescriptorSet {
RHI::RHIDescriptorPool* pool = nullptr;
RHI::RHIDescriptorSet* set = nullptr;
@@ -189,12 +187,22 @@ private:
const Resources::Shader* shader = nullptr;
Containers::String passName;
Containers::String keywordSignature;
Core::uint32 renderTargetCount = 0;
std::array<Core::uint32, 8> renderTargetFormats = {};
Core::uint32 depthStencilFormat = 0;
Core::uint32 sampleCount = 1;
Core::uint32 sampleQuality = 0;
bool operator==(const PipelineStateKey& other) const {
return renderState == other.renderState &&
shader == other.shader &&
passName == other.passName &&
keywordSignature == other.keywordSignature;
keywordSignature == other.keywordSignature &&
renderTargetCount == other.renderTargetCount &&
renderTargetFormats == other.renderTargetFormats &&
depthStencilFormat == other.depthStencilFormat &&
sampleCount == other.sampleCount &&
sampleQuality == other.sampleQuality;
}
};
@@ -208,6 +216,46 @@ private:
combine(reinterpret_cast<size_t>(key.shader));
combine(std::hash<Containers::String>{}(key.passName));
combine(std::hash<Containers::String>{}(key.keywordSignature));
combine(std::hash<Core::uint32>{}(key.renderTargetCount));
for (Core::uint32 format : key.renderTargetFormats) {
combine(std::hash<Core::uint32>{}(format));
}
combine(std::hash<Core::uint32>{}(key.depthStencilFormat));
combine(std::hash<Core::uint32>{}(key.sampleCount));
combine(std::hash<Core::uint32>{}(key.sampleQuality));
return hash;
}
};
struct SkyboxPipelineStateKey {
Core::uint32 renderTargetCount = 0;
std::array<Core::uint32, 8> renderTargetFormats = {};
Core::uint32 depthStencilFormat = 0;
Core::uint32 sampleCount = 1;
Core::uint32 sampleQuality = 0;
bool operator==(const SkyboxPipelineStateKey& other) const {
return renderTargetCount == other.renderTargetCount &&
renderTargetFormats == other.renderTargetFormats &&
depthStencilFormat == other.depthStencilFormat &&
sampleCount == other.sampleCount &&
sampleQuality == other.sampleQuality;
}
};
struct SkyboxPipelineStateKeyHash {
size_t operator()(const SkyboxPipelineStateKey& key) const noexcept {
size_t hash = std::hash<Core::uint32>{}(key.renderTargetCount);
auto combine = [&hash](size_t value) {
hash ^= value + 0x9e3779b9u + (hash << 6) + (hash >> 2);
};
for (Core::uint32 format : key.renderTargetFormats) {
combine(std::hash<Core::uint32>{}(format));
}
combine(std::hash<Core::uint32>{}(key.depthStencilFormat));
combine(std::hash<Core::uint32>{}(key.sampleCount));
combine(std::hash<Core::uint32>{}(key.sampleQuality));
return hash;
}
};
@@ -226,8 +274,12 @@ private:
const ResolvedShaderPass& resolvedShaderPass);
RHI::RHIPipelineState* GetOrCreatePipelineState(
const RenderContext& context,
const RenderSurface& surface,
const RenderSceneData& sceneData,
const Resources::Material* material);
RHI::RHIPipelineState* GetOrCreateSkyboxPipelineState(
const RenderContext& context,
const RenderSurface& surface);
bool CreateOwnedDescriptorSet(
const BuiltinPassSetLayoutMetadata& setLayout,
OwnedDescriptorSet& descriptorSet);
@@ -263,10 +315,12 @@ private:
bool ExecuteForwardTransparentPass(const RenderPassContext& context);
bool DrawVisibleItems(
const RenderContext& context,
const RenderSurface& surface,
const RenderSceneData& sceneData,
bool drawTransparentItems);
bool DrawVisibleItem(
const RenderContext& context,
const RenderSurface& surface,
const RenderSceneData& sceneData,
const VisibleRenderItem& visibleItem);
bool EnsureSkyboxResources(const RenderContext& context);
@@ -292,7 +346,8 @@ private:
RHI::RHITexture* m_fallbackTextureCube = nullptr;
RHI::RHIResourceView* m_fallbackTextureCubeView = nullptr;
RHI::RHIPipelineLayout* m_skyboxPipelineLayout = nullptr;
RHI::RHIPipelineState* m_skyboxPipelineState = nullptr;
Containers::String m_skyboxPassName;
std::unordered_map<SkyboxPipelineStateKey, RHI::RHIPipelineState*, SkyboxPipelineStateKeyHash> m_skyboxPipelineStates;
OwnedDescriptorSet m_skyboxEnvironmentSet = {};
OwnedDescriptorSet m_skyboxMaterialSet = {};
OwnedDescriptorSet m_skyboxPanoramicTextureSet = {};
@@ -300,7 +355,7 @@ private:
OwnedDescriptorSet m_skyboxSamplerSet = {};
RHI::RHIResourceView* m_skyboxBoundPanoramicTextureView = nullptr;
RHI::RHIResourceView* m_skyboxBoundCubemapTextureView = nullptr;
RenderPassSequence m_passSequence;
std::unique_ptr<Passes::BuiltinVolumetricPass> m_volumetricPass;
};
class BuiltinForwardPipelineAsset final : public RenderPipelineAsset {