ソースを参照

Add support of Variable Rate Shading image on the Features/OpenXR sample (#568)

* Add support of Variable Rate Shading image on the Features/OpenXR sample

Signed-off-by: Akio Gaule <[email protected]>
Akio Gaule 2 年 前
コミット
81b5762d80

+ 16 - 2
Gem/Code/Source/SampleComponentManager.cpp

@@ -29,10 +29,12 @@
 #include <Atom/RPI.Public/Scene.h>
 #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
 #include <Atom/RPI.Reflect/Image/AttachmentImageAsset.h>
+#include <Atom/RPI.Reflect/Image/AttachmentImageAssetCreator.h>
 #include <Atom/RPI.Reflect/Shader/IShaderVariantFinder.h>
 
 #include <Atom/RHI/Factory.h>
 #include <Atom/RHI/RHISystemInterface.h>
+#include <Atom/RHI/RHIUtils.h>
 #include <Atom/RHI.Reflect/AliasedHeapEnums.h>
 
 #include <Automation/ScriptManager.h>
@@ -570,6 +572,7 @@ namespace AtomSampleViewer
 
         m_windowContext = nullptr;
         m_brdfTexture.reset();
+        m_xrVrsTexture.reset();
 
         ReleaseRHIScene();
         ReleaseRPIScene();
@@ -1749,18 +1752,29 @@ namespace AtomSampleViewer
 
         if (xrSystem)
         {
+            RHI::Ptr<RHI::Device> device = Utils::GetRHIDevice();
+            if (RHI::CheckBitsAll(device->GetFeatures().m_shadingRateTypeMask, RHI::ShadingRateTypeFlags::PerRegion) && !m_xrVrsTexture)
+            {
+                auto* xrRPISystem = AZ::RPI::RPISystemInterface::Get()->GetXRSystem();
+                // Need to fill the contents of the Variable shade rating image.
+                const AZStd::shared_ptr<const RPI::PassTemplate> forwardTemplate =
+                    RPI::PassSystemInterface::Get()->GetPassTemplate(Name("MultiViewForwardPassTemplate"));
+
+                m_xrVrsTexture = xrRPISystem->InitPassFoveatedAttachment(*forwardTemplate);
+            }
+
             RPI::RenderPipelineDescriptor xrPipelineDesc;
             xrPipelineDesc.m_mainViewTagName = "MainCamera";
             xrPipelineDesc.m_renderSettings.m_multisampleState.m_samples = static_cast<uint16_t>(m_numMSAASamples);
 
             // Build the pipeline for left eye
             xrPipelineDesc.m_name = "RPISamplePipelineXRLeft";
-            xrPipelineDesc.m_rootPassTemplate = "LowEndPipelineXRLeftTemplate";
+            xrPipelineDesc.m_rootPassTemplate = "MultiViewXRLeftPipelineTemplate";
             RPI::RenderPipelinePtr renderPipelineLeft = RPI::RenderPipeline::CreateRenderPipelineForWindow(xrPipelineDesc, *m_windowContext.get(), AZ::RPI::ViewType::XrLeft);
 
             // Build the pipeline for right eye
             xrPipelineDesc.m_name = "RHISamplePipelineXRRight";
-            xrPipelineDesc.m_rootPassTemplate = "LowEndPipelineXRRightTemplate";
+            xrPipelineDesc.m_rootPassTemplate = "MultiViewXRRightPipelineTemplate";
             RPI::RenderPipelinePtr renderPipelineRight = RPI::RenderPipeline::CreateRenderPipelineForWindow(xrPipelineDesc, *m_windowContext.get(), AZ::RPI::ViewType::XrRight);
 
             //Add both the pipelines to the scene

+ 1 - 0
Gem/Code/Source/SampleComponentManager.h

@@ -200,6 +200,7 @@ namespace AtomSampleViewer
         AZ::Entity* m_cameraEntity = nullptr;
 
         AZ::Data::Instance<AZ::RPI::AttachmentImage> m_brdfTexture;
+        AZ::Data::Instance<AZ::RPI::AttachmentImage> m_xrVrsTexture;
 
         int32_t m_selectedSampleIndex = -1;
 

+ 9 - 0
Registry/openxr.setreg

@@ -0,0 +1,9 @@
+{
+    "O3DE": {
+        "Atom": {
+            "OpenXR": {
+                "FoveatedLevel" : 2
+            }
+        }
+    }
+}