diff --git a/Hydrogent/CMakeLists.txt b/Hydrogent/CMakeLists.txt index 8d4edc3a..1c856d45 100644 --- a/Hydrogent/CMakeLists.txt +++ b/Hydrogent/CMakeLists.txt @@ -9,7 +9,6 @@ set(SOURCE src/HnBuffer.cpp src/HnRenderBuffer.cpp src/HnRenderDelegate.cpp - src/HnRendererImpl.cpp src/HnRenderPass.cpp src/HnShaderSourceFactory.cpp src/HnRenderPassState.cpp @@ -39,10 +38,10 @@ set(INTERFACE interface/HnBuffer.hpp interface/HnRenderBuffer.hpp interface/HnRenderDelegate.hpp - interface/HnRendererImpl.hpp interface/HnRenderPass.hpp interface/HnRenderPassState.hpp interface/HnTokens.hpp + interface/HnTypes.hpp interface/HnTextureIdentifier.hpp interface/HnTextureRegistry.hpp interface/Tasks/HnTask.hpp @@ -52,8 +51,6 @@ set(INTERFACE interface/Tasks/HnPostProcessTask.hpp interface/Tasks/HnReadRprimIdTask.hpp interface/Tasks/HnTaskManager.hpp - interface/HnTypes.hpp - interface/HnRenderer.hpp ) file(GLOB_RECURSE SHADERS LIST_DIRECTORIES false shaders/*.*) diff --git a/Hydrogent/interface/HnRenderer.hpp b/Hydrogent/interface/HnRenderer.hpp deleted file mode 100644 index c8595398..00000000 --- a/Hydrogent/interface/HnRenderer.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2023 Diligent Graphics LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "../../../Primitives/interface/Object.h" -#include "../../../Graphics/GraphicsEngine/interface/RenderDevice.h" -#include "../../../Graphics/GraphicsEngine/interface/DeviceContext.h" - -#include "HnTypes.hpp" - -#include "pxr/usd/usd/stage.h" - -namespace Diligent -{ - -namespace USD -{ - -// {EA95099B-E894-47A6-AF33-B20096C4CF44} -static const INTERFACE_ID IID_HnRenderer = - {0xea95099b, 0xe894, 0x47a6, {0xaf, 0x33, 0xb2, 0x0, 0x96, 0xc4, 0xcf, 0x44}}; - -struct HnRendererCreateInfo -{ - /// Render target format. - TEXTURE_FORMAT RTVFormat = TEX_FORMAT_UNKNOWN; - - /// Depth-buffer format. - TEXTURE_FORMAT DSVFormat = TEX_FORMAT_UNKNOWN; - - bool FrontCCW = false; - - bool ConvertOutputToSRGB = false; - - /// Camera attributes constant buffer. - IBuffer* pCameraAttribsCB = nullptr; - - /// Light attributes constant buffer. - IBuffer* pLightAttribsCB = nullptr; -}; - -struct HnDrawAttribs -{ - ITextureView* pDstRTV = nullptr; - - float AverageLogLum = 0.3f; - float MiddleGray = 0.18f; - float WhitePoint = 3.0f; - - bool EnablePrimIdQueries = false; - - float4 WireframeColor = float4{1, 1, 1, 1}; - float4 SlectionColor = float4{0.75f, 0.75f, 0.25f, 0.5f}; - - const pxr::SdfPath* SelectedPrim = nullptr; -}; - -struct HnRenderParams -{ - float4x4 Transform = float4x4::Identity(); - - int DebugView = 0; - float OcclusionStrength = 1; - float EmissionScale = 1; - float IBLScale = 1; - - HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; - - bool FrontFaceCCW = false; -}; - -class IHnRenderer : public IObject -{ -public: - virtual void LoadUSDStage(pxr::UsdStageRefPtr& Stage) = 0; - - virtual void Update() = 0; - - virtual void SetParams(const HnRenderParams& Params) = 0; - - virtual void Draw(IDeviceContext* pCtx, const HnDrawAttribs& Attribs) = 0; - - virtual void SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvironmentMapSRV) = 0; - - /// Queries primitive Id from the previously rendered primitive Id texture. - /// - /// \param [in] pCtx - device context to run graphics commands. - /// \param [in] X - query x coordinate. - /// \param [in] Y - query x coordinate. - /// - /// \return If query result is not available, returns nullptr. - /// If query result is available, but no primitive is selected, returns empty string. - /// Otherwise, returns the primitive SDF path. - /// - /// \remarks Only a single query per frame is supported. - virtual const pxr::SdfPath* QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) = 0; -}; - -void CreateHnRenderer(IRenderDevice* pDevice, IDeviceContext* pContext, const HnRendererCreateInfo& CI, IHnRenderer** ppRenderer); - -} // namespace USD - -} // namespace Diligent diff --git a/Hydrogent/interface/HnRendererImpl.hpp b/Hydrogent/interface/HnRendererImpl.hpp deleted file mode 100644 index 70bf3d2d..00000000 --- a/Hydrogent/interface/HnRendererImpl.hpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2023 Diligent Graphics LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include -#include -#include - -#include "HnRenderer.hpp" - -#include "../../../DiligentCore/Graphics/GraphicsTools/interface/RenderStateCache.hpp" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" -#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" -#include "../../../DiligentCore/Common/interface/BasicMath.hpp" -#include "../../../DiligentCore/Common/interface/ObjectBase.hpp" - -#include "Tasks/HnTaskManager.hpp" - -#include "pxr/usd/usd/stage.h" -#include "pxr/imaging/hd/tokens.h" -#include "pxr/imaging/hd/renderIndex.h" -#include "pxr/imaging/hd/engine.h" -#include "pxr/usdImaging/usdImaging/delegate.h" - - -namespace Diligent -{ - -namespace USD -{ - -class HnRenderDelegate; -class HnMesh; -class HnMaterial; - -class HnRendererImpl final : public ObjectBase -{ -public: - using TBase = ObjectBase; - - // {B8E2E916-B4E6-4C1E-A2DD-78FCD763F43E} - static constexpr INTERFACE_ID IID_Impl = - {0xb8e2e916, 0xb4e6, 0x4c1e, {0xa2, 0xdd, 0x78, 0xfc, 0xd7, 0x63, 0xf4, 0x3e}}; - - HnRendererImpl(IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, - IDeviceContext* pContext, - const HnRendererCreateInfo& CI); - ~HnRendererImpl(); - - IMPLEMENT_QUERY_INTERFACE2_IN_PLACE(IID_HnRenderer, IID_Impl, TBase) - - virtual void LoadUSDStage(pxr::UsdStageRefPtr& Stage) override final; - virtual void Update() override final; - virtual void SetParams(const HnRenderParams& Params) override final; - virtual void Draw(IDeviceContext* pCtx, const HnDrawAttribs& Attribs) override final; - virtual void SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvironmentMapSRV) override final; - - virtual const pxr::SdfPath* QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) override final; - -private: - void DestroyStageResources(); - -private: - RenderDeviceWithCache_N m_Device; - RefCntAutoPtr m_Context; - - RefCntAutoPtr m_CameraAttribsCB; - RefCntAutoPtr m_LightAttribsCB; - - const bool m_ConvertOutputToSRGB; - - pxr::UsdStageRefPtr m_Stage; - - std::unique_ptr m_RenderDelegate; - std::unique_ptr m_RenderIndex; - std::unique_ptr m_ImagingDelegate; - std::unique_ptr m_TaskManager; - - pxr::HdEngine m_Engine; - - static constexpr TEXTURE_FORMAT ColorBufferFormat = TEX_FORMAT_RGBA16_FLOAT; - static constexpr TEXTURE_FORMAT MeshIdFormat = TEX_FORMAT_R32_FLOAT; - static constexpr TEXTURE_FORMAT DepthFormat = TEX_FORMAT_D32_FLOAT; - - HnRenderParams m_RenderParams; - bool m_RenderParamsChanged = true; - - pxr::SdfPath m_FinalColorTargetId; -}; - -} // namespace USD - -} // namespace Diligent diff --git a/Hydrogent/src/HnRendererImpl.cpp b/Hydrogent/src/HnRendererImpl.cpp deleted file mode 100644 index a188c3d4..00000000 --- a/Hydrogent/src/HnRendererImpl.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2023 Diligent Graphics LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "HnRendererImpl.hpp" -#include "HnRenderDelegate.hpp" -#include "HnMesh.hpp" -#include "HnMaterial.hpp" -#include "HnTokens.hpp" -#include "Tasks/HnTaskManager.hpp" -#include "Tasks/HnSetupRenderingTask.hpp" -#include "Tasks/HnPostProcessTask.hpp" - -#include "EngineMemory.h" -#include "USD_Renderer.hpp" -#include "HnRenderBuffer.hpp" - -#include "pxr/imaging/hd/task.h" -#include "pxr/imaging/hd/tokens.h" -#include "pxr/imaging/hd/renderPass.h" - -namespace Diligent -{ - -namespace USD -{ - -void CreateHnRenderer(IRenderDevice* pDevice, IDeviceContext* pContext, const HnRendererCreateInfo& CI, IHnRenderer** ppRenderer) -{ - auto* pRenderer = NEW_RC_OBJ(GetRawAllocator(), "HnRenderer instance", HnRendererImpl)(pDevice, pContext, CI); - pRenderer->QueryInterface(IID_HnRenderer, reinterpret_cast(ppRenderer)); -} - -HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, - IDeviceContext* pContext, - const HnRendererCreateInfo& CI) : - TBase{pRefCounters}, - m_Device{pDevice}, - m_Context{pContext}, - m_CameraAttribsCB{CI.pCameraAttribsCB}, - m_LightAttribsCB{CI.pLightAttribsCB}, - m_ConvertOutputToSRGB{CI.ConvertOutputToSRGB} -{ -} - -HnRendererImpl::~HnRendererImpl() -{ - DestroyStageResources(); -} - -void HnRendererImpl::DestroyStageResources() -{ - m_TaskManager.reset(); - m_ImagingDelegate.reset(); - m_RenderIndex.reset(); - m_RenderDelegate.reset(); - m_Stage.Reset(); -} - -void HnRendererImpl::LoadUSDStage(pxr::UsdStageRefPtr& Stage) -{ - DestroyStageResources(); - - m_Stage = Stage; - - m_RenderDelegate = HnRenderDelegate::Create({m_Device, m_Context, nullptr, m_CameraAttribsCB, m_LightAttribsCB}); - m_RenderIndex.reset(pxr::HdRenderIndex::New(m_RenderDelegate.get(), pxr::HdDriverVector{})); - - const pxr::SdfPath SceneDelegateId = pxr::SdfPath::AbsoluteRootPath(); - - m_ImagingDelegate = std::make_unique(m_RenderIndex.get(), SceneDelegateId); - m_ImagingDelegate->Populate(m_Stage->GetPseudoRoot()); - - const pxr::SdfPath TaskManagerId = SceneDelegateId.AppendChild(pxr::TfToken{"_HnTaskManager_"}); - m_TaskManager = std::make_unique(*m_RenderIndex, TaskManagerId); - - m_FinalColorTargetId = SceneDelegateId.AppendChild(pxr::TfToken{"_HnFinalColorTarget_"}); - m_RenderIndex->InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, m_ImagingDelegate.get(), m_FinalColorTargetId); - - { - HnPostProcessTaskParams Params; - Params.ConvertOutputToSRGB = m_ConvertOutputToSRGB; - Params.ToneMappingMode = 4; // Uncharted2 - m_TaskManager->SetTaskParams(HnTaskManager::TaskUID_PostProcess, Params); - } -} - -void HnRendererImpl::SetParams(const HnRenderParams& Params) -{ - m_RenderParams = Params; - m_RenderParamsChanged = true; -} - -void HnRendererImpl::Update() -{ - if (!m_RenderDelegate || !m_ImagingDelegate) - return; - - if (m_RenderParamsChanged) - { - HnSetupRenderingTaskParams Params; - Params.ColorFormat = ColorBufferFormat; - Params.MeshIdFormat = MeshIdFormat; - Params.DepthFormat = DepthFormat; - Params.RenderMode = m_RenderParams.RenderMode; - Params.FrontFaceCCW = m_RenderParams.FrontFaceCCW; - Params.DebugView = m_RenderParams.DebugView; - Params.OcclusionStrength = m_RenderParams.OcclusionStrength; - Params.EmissionScale = m_RenderParams.EmissionScale; - Params.IBLScale = m_RenderParams.IBLScale; - Params.Transform = m_RenderParams.Transform; - Params.FinalColorTargetId = m_FinalColorTargetId; - m_TaskManager->SetTaskParams(HnTaskManager::TaskUID_SetupRendering, Params); - - m_RenderParamsChanged = false; - } - - m_ImagingDelegate->ApplyPendingUpdates(); -} - -void HnRendererImpl::Draw(IDeviceContext* pCtx, const HnDrawAttribs& Attribs) -{ - if (!m_RenderDelegate) - return; - - auto* FinalColorTarget = static_cast(m_RenderIndex->GetBprim(pxr::HdPrimTypeTokens->renderBuffer, m_FinalColorTargetId)); - VERIFY_EXPR(FinalColorTarget != nullptr); - FinalColorTarget->SetTarget(Attribs.pDstRTV); - - pxr::HdTaskSharedPtrVector tasks = m_TaskManager->GetTasks(); - m_Engine.Execute(&m_ImagingDelegate->GetRenderIndex(), &tasks); - - FinalColorTarget->ReleaseTarget(); -} - -void HnRendererImpl::SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvironmentMapSRV) -{ - m_RenderDelegate->GetUSDRenderer()->PrecomputeCubemaps(pCtx, pEnvironmentMapSRV); -} - -const pxr::SdfPath* HnRendererImpl::QueryPrimId(IDeviceContext* pCtx, Uint32 X, Uint32 Y) -{ - return nullptr; -#if 0 - if (!m_MeshIdTexture) - return nullptr; - - Uint32 MeshUid = ~0u; - - - static const pxr::SdfPath EmptyPath; - if (MeshUid == ~0u) - return nullptr; - else - return MeshUid != 0 ? m_RenderDelegate->GetMeshPrimId(MeshUid) : &EmptyPath; -#endif -} - -} // namespace USD - -} // namespace Diligent