refactor: move builtin forward draw submission internal
This commit is contained in:
@@ -518,7 +518,7 @@ add_library(XCEngine STATIC
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Execution/SceneRenderer.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Execution/SceneRenderer.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/BuiltinForwardPipeline.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/BuiltinForwardPipeline.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/Internal/BuiltinForwardPipelineSkybox.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/Internal/BuiltinForwardPipelineSkybox.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/BuiltinForwardPipelineResources.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Rendering/Pipelines/Internal/BuiltinForwardPipelineResources.cpp
|
||||||
|
|
||||||
# Scene
|
# Scene
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Scene/Scene.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Scene/Scene.h
|
||||||
|
|||||||
@@ -289,40 +289,6 @@ bool BuiltinForwardPipeline::ExecuteForwardTransparentPass(const RenderPassConte
|
|||||||
return DrawVisibleItems(context, surface, sceneData, true);
|
return DrawVisibleItems(context, surface, sceneData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuiltinForwardPipeline::DrawVisibleItems(
|
|
||||||
const RenderContext& context,
|
|
||||||
const RenderSurface& surface,
|
|
||||||
const RenderSceneData& sceneData,
|
|
||||||
bool drawTransparentItems) {
|
|
||||||
RHI::RHICommandList* commandList = context.commandList;
|
|
||||||
RHI::RHIPipelineState* currentPipelineState = nullptr;
|
|
||||||
for (const VisibleRenderItem& visibleItem : sceneData.visibleItems) {
|
|
||||||
const bool isTransparentItem = IsTransparentRenderQueue(visibleItem.renderQueue);
|
|
||||||
if (isTransparentItem != drawTransparentItems) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Resources::Material* material = ResolveMaterial(visibleItem);
|
|
||||||
BuiltinMaterialPass pass = BuiltinMaterialPass::ForwardLit;
|
|
||||||
if (!TryResolveSurfacePassType(material, pass)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
RHI::RHIPipelineState* pipelineState = GetOrCreatePipelineState(context, surface, sceneData, material);
|
|
||||||
if (pipelineState == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (pipelineState != currentPipelineState) {
|
|
||||||
commandList->SetPipelineState(pipelineState);
|
|
||||||
currentPipelineState = pipelineState;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawVisibleItem(context, surface, sceneData, visibleItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BuiltinForwardPipeline::EnsureInitialized(const RenderContext& context) {
|
bool BuiltinForwardPipeline::EnsureInitialized(const RenderContext& context) {
|
||||||
if (!context.IsValid()) {
|
if (!context.IsValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#include "RHI/RHICommandList.h"
|
#include "RHI/RHICommandList.h"
|
||||||
#include "RHI/RHIDevice.h"
|
#include "RHI/RHIDevice.h"
|
||||||
#include "Rendering/Builtin/BuiltinPassLayoutUtils.h"
|
#include "Rendering/Builtin/BuiltinPassLayoutUtils.h"
|
||||||
#include "Rendering/Detail/ShaderVariantUtils.h"
|
#include "Rendering/Internal/RenderSurfacePipelineUtils.h"
|
||||||
|
#include "Rendering/Internal/ShaderVariantUtils.h"
|
||||||
#include "Rendering/Materials/RenderMaterialResolve.h"
|
#include "Rendering/Materials/RenderMaterialResolve.h"
|
||||||
#include "Rendering/Materials/RenderMaterialStateUtils.h"
|
#include "Rendering/Materials/RenderMaterialStateUtils.h"
|
||||||
#include "Resources/Material/Material.h"
|
#include "Resources/Material/Material.h"
|
||||||
@@ -41,7 +42,7 @@ const Resources::ShaderPass* FindCompatibleSurfacePass(
|
|||||||
|
|
||||||
for (const Resources::ShaderPass& shaderPass : shader.GetPasses()) {
|
for (const Resources::ShaderPass& shaderPass : shader.GetPasses()) {
|
||||||
if (ShaderPassMatchesBuiltinPass(shaderPass, pass) &&
|
if (ShaderPassMatchesBuiltinPass(shaderPass, pass) &&
|
||||||
::XCEngine::Rendering::Detail::ShaderPassHasGraphicsVariants(
|
::XCEngine::Rendering::Internal::ShaderPassHasGraphicsVariants(
|
||||||
shader,
|
shader,
|
||||||
shaderPass.name,
|
shaderPass.name,
|
||||||
backend,
|
backend,
|
||||||
@@ -60,25 +61,23 @@ RHI::GraphicsPipelineDesc CreatePipelineDesc(
|
|||||||
const Resources::ShaderPass& shaderPass,
|
const Resources::ShaderPass& shaderPass,
|
||||||
const Containers::String& passName,
|
const Containers::String& passName,
|
||||||
const Resources::ShaderKeywordSet& keywordSet,
|
const Resources::ShaderKeywordSet& keywordSet,
|
||||||
const Resources::Material* material) {
|
const Resources::Material* material,
|
||||||
|
const RenderSurface& surface) {
|
||||||
RHI::GraphicsPipelineDesc pipelineDesc = {};
|
RHI::GraphicsPipelineDesc pipelineDesc = {};
|
||||||
pipelineDesc.pipelineLayout = pipelineLayout;
|
pipelineDesc.pipelineLayout = pipelineLayout;
|
||||||
pipelineDesc.topologyType = static_cast<uint32_t>(RHI::PrimitiveTopologyType::Triangle);
|
pipelineDesc.topologyType = static_cast<uint32_t>(RHI::PrimitiveTopologyType::Triangle);
|
||||||
pipelineDesc.renderTargetCount = 1;
|
::XCEngine::Rendering::Internal::ApplySurfacePropertiesToGraphicsPipelineDesc(surface, pipelineDesc);
|
||||||
pipelineDesc.renderTargetFormats[0] = static_cast<uint32_t>(RHI::Format::R8G8B8A8_UNorm);
|
|
||||||
pipelineDesc.depthStencilFormat = static_cast<uint32_t>(RHI::Format::D24_UNorm_S8_UInt);
|
|
||||||
pipelineDesc.sampleCount = 1;
|
|
||||||
ApplyResolvedRenderState(&shaderPass, material, pipelineDesc);
|
ApplyResolvedRenderState(&shaderPass, material, pipelineDesc);
|
||||||
|
|
||||||
pipelineDesc.inputLayout = BuiltinForwardPipeline::BuildInputLayout();
|
pipelineDesc.inputLayout = BuiltinForwardPipeline::BuildInputLayout();
|
||||||
|
|
||||||
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Detail::ToShaderBackend(backendType);
|
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Internal::ToShaderBackend(backendType);
|
||||||
const Resources::ShaderStageVariant* vertexVariant =
|
const Resources::ShaderStageVariant* vertexVariant =
|
||||||
shader.FindVariant(passName, Resources::ShaderType::Vertex, backend, keywordSet);
|
shader.FindVariant(passName, Resources::ShaderType::Vertex, backend, keywordSet);
|
||||||
const Resources::ShaderStageVariant* fragmentVariant =
|
const Resources::ShaderStageVariant* fragmentVariant =
|
||||||
shader.FindVariant(passName, Resources::ShaderType::Fragment, backend, keywordSet);
|
shader.FindVariant(passName, Resources::ShaderType::Fragment, backend, keywordSet);
|
||||||
if (vertexVariant != nullptr) {
|
if (vertexVariant != nullptr) {
|
||||||
::XCEngine::Rendering::Detail::ApplyShaderStageVariant(
|
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
|
||||||
shader.GetPath(),
|
shader.GetPath(),
|
||||||
shaderPass,
|
shaderPass,
|
||||||
backend,
|
backend,
|
||||||
@@ -86,7 +85,7 @@ RHI::GraphicsPipelineDesc CreatePipelineDesc(
|
|||||||
pipelineDesc.vertexShader);
|
pipelineDesc.vertexShader);
|
||||||
}
|
}
|
||||||
if (fragmentVariant != nullptr) {
|
if (fragmentVariant != nullptr) {
|
||||||
::XCEngine::Rendering::Detail::ApplyShaderStageVariant(
|
::XCEngine::Rendering::Internal::ApplyShaderStageVariant(
|
||||||
shader.GetPath(),
|
shader.GetPath(),
|
||||||
shaderPass,
|
shaderPass,
|
||||||
backend,
|
backend,
|
||||||
@@ -124,7 +123,7 @@ BuiltinForwardPipeline::ResolvedShaderPass BuiltinForwardPipeline::ResolveSurfac
|
|||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Detail::ToShaderBackend(m_backendType);
|
const Resources::ShaderBackend backend = ::XCEngine::Rendering::Internal::ToShaderBackend(m_backendType);
|
||||||
|
|
||||||
if (material != nullptr && material->GetShader() != nullptr) {
|
if (material != nullptr && material->GetShader() != nullptr) {
|
||||||
const Resources::Shader* materialShader = material->GetShader();
|
const Resources::Shader* materialShader = material->GetShader();
|
||||||
@@ -236,6 +235,7 @@ BuiltinForwardPipeline::PassResourceLayout* BuiltinForwardPipeline::GetOrCreateP
|
|||||||
|
|
||||||
RHI::RHIPipelineState* BuiltinForwardPipeline::GetOrCreatePipelineState(
|
RHI::RHIPipelineState* BuiltinForwardPipeline::GetOrCreatePipelineState(
|
||||||
const RenderContext& context,
|
const RenderContext& context,
|
||||||
|
const RenderSurface& surface,
|
||||||
const RenderSceneData& sceneData,
|
const RenderSceneData& sceneData,
|
||||||
const Resources::Material* material) {
|
const Resources::Material* material) {
|
||||||
const Resources::ShaderKeywordSet keywordSet = ResolvePassKeywordSet(sceneData, material);
|
const Resources::ShaderKeywordSet keywordSet = ResolvePassKeywordSet(sceneData, material);
|
||||||
@@ -257,7 +257,15 @@ RHI::RHIPipelineState* BuiltinForwardPipeline::GetOrCreatePipelineState(
|
|||||||
BuildStaticPipelineRenderStateKey(ResolveEffectiveRenderState(resolvedShaderPass.pass, material));
|
BuildStaticPipelineRenderStateKey(ResolveEffectiveRenderState(resolvedShaderPass.pass, material));
|
||||||
pipelineKey.shader = resolvedShaderPass.shader;
|
pipelineKey.shader = resolvedShaderPass.shader;
|
||||||
pipelineKey.passName = resolvedShaderPass.passName;
|
pipelineKey.passName = resolvedShaderPass.passName;
|
||||||
pipelineKey.keywordSignature = ::XCEngine::Rendering::Detail::BuildShaderKeywordSignature(keywordSet);
|
pipelineKey.keywordSignature = ::XCEngine::Rendering::Internal::BuildShaderKeywordSignature(keywordSet);
|
||||||
|
pipelineKey.renderTargetCount =
|
||||||
|
::XCEngine::Rendering::Internal::ResolveSurfaceColorAttachmentCount(surface);
|
||||||
|
pipelineKey.renderTargetFormats =
|
||||||
|
::XCEngine::Rendering::Internal::ResolveSurfaceColorFormats(surface);
|
||||||
|
pipelineKey.depthStencilFormat =
|
||||||
|
static_cast<Core::uint32>(::XCEngine::Rendering::Internal::ResolveSurfaceDepthFormat(surface));
|
||||||
|
pipelineKey.sampleCount = ::XCEngine::Rendering::Internal::ResolveSurfaceSampleCount(surface);
|
||||||
|
pipelineKey.sampleQuality = ::XCEngine::Rendering::Internal::ResolveSurfaceSampleQuality(surface);
|
||||||
|
|
||||||
const auto existing = m_pipelineStates.find(pipelineKey);
|
const auto existing = m_pipelineStates.find(pipelineKey);
|
||||||
if (existing != m_pipelineStates.end()) {
|
if (existing != m_pipelineStates.end()) {
|
||||||
@@ -272,7 +280,8 @@ RHI::RHIPipelineState* BuiltinForwardPipeline::GetOrCreatePipelineState(
|
|||||||
*resolvedShaderPass.pass,
|
*resolvedShaderPass.pass,
|
||||||
resolvedShaderPass.passName,
|
resolvedShaderPass.passName,
|
||||||
keywordSet,
|
keywordSet,
|
||||||
material);
|
material,
|
||||||
|
surface);
|
||||||
RHI::RHIPipelineState* pipelineState = context.device->CreatePipelineState(pipelineDesc);
|
RHI::RHIPipelineState* pipelineState = context.device->CreatePipelineState(pipelineDesc);
|
||||||
if (pipelineState == nullptr || !pipelineState->IsValid()) {
|
if (pipelineState == nullptr || !pipelineState->IsValid()) {
|
||||||
Debug::Logger::Get().Error(
|
Debug::Logger::Get().Error(
|
||||||
@@ -621,8 +630,10 @@ BuiltinForwardPipeline::AdditionalLightConstants BuiltinForwardPipeline::BuildAd
|
|||||||
|
|
||||||
bool BuiltinForwardPipeline::DrawVisibleItem(
|
bool BuiltinForwardPipeline::DrawVisibleItem(
|
||||||
const RenderContext& context,
|
const RenderContext& context,
|
||||||
|
const RenderSurface& surface,
|
||||||
const RenderSceneData& sceneData,
|
const RenderSceneData& sceneData,
|
||||||
const VisibleRenderItem& visibleItem) {
|
const VisibleRenderItem& visibleItem) {
|
||||||
|
(void)surface;
|
||||||
const RenderResourceCache::CachedMesh* cachedMesh = m_resourceCache.GetOrCreateMesh(m_device, visibleItem.mesh);
|
const RenderResourceCache::CachedMesh* cachedMesh = m_resourceCache.GetOrCreateMesh(m_device, visibleItem.mesh);
|
||||||
if (cachedMesh == nullptr || cachedMesh->vertexBufferView == nullptr) {
|
if (cachedMesh == nullptr || cachedMesh->vertexBufferView == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
@@ -795,6 +806,40 @@ bool BuiltinForwardPipeline::DrawVisibleItem(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BuiltinForwardPipeline::DrawVisibleItems(
|
||||||
|
const RenderContext& context,
|
||||||
|
const RenderSurface& surface,
|
||||||
|
const RenderSceneData& sceneData,
|
||||||
|
bool drawTransparentItems) {
|
||||||
|
RHI::RHICommandList* commandList = context.commandList;
|
||||||
|
RHI::RHIPipelineState* currentPipelineState = nullptr;
|
||||||
|
for (const VisibleRenderItem& visibleItem : sceneData.visibleItems) {
|
||||||
|
const bool isTransparentItem = IsTransparentRenderQueue(visibleItem.renderQueue);
|
||||||
|
if (isTransparentItem != drawTransparentItems) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Resources::Material* material = ResolveMaterial(visibleItem);
|
||||||
|
BuiltinMaterialPass pass = BuiltinMaterialPass::ForwardLit;
|
||||||
|
if (!TryResolveSurfacePassType(material, pass)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RHI::RHIPipelineState* pipelineState = GetOrCreatePipelineState(context, surface, sceneData, material);
|
||||||
|
if (pipelineState == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (pipelineState != currentPipelineState) {
|
||||||
|
commandList->SetPipelineState(pipelineState);
|
||||||
|
currentPipelineState = pipelineState;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawVisibleItem(context, surface, sceneData, visibleItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Pipelines
|
} // namespace Pipelines
|
||||||
} // namespace Rendering
|
} // namespace Rendering
|
||||||
} // namespace XCEngine
|
} // namespace XCEngine
|
||||||
Reference in New Issue
Block a user