@@ -28,6 +28,8 @@ Unit-tests of the RHI RenderPass
2828#include < Methane/Graphics/RHI/RenderPattern.h>
2929#include < Methane/Graphics/RHI/RenderPass.h>
3030#include < Methane/Graphics/RHI/ObjectRegistry.h>
31+ #include < Methane/Graphics/Base/RenderPass.h>
32+ #include < Methane/Graphics/Base/Texture.h>
3133
3234#include < memory>
3335#include < taskflow/taskflow.hpp>
@@ -132,6 +134,25 @@ TEST_CASE("RHI Render Pass Functions", "[rhi][render][pass]")
132134 CHECK (render_pass.GetSettings () == new_render_pass_resources.settings );
133135 }
134136
137+ SECTION (" Update Settings Invalidates Attachment Textures Cache" )
138+ {
139+ const auto & base_render_pass = dynamic_cast <const Base::RenderPass&>(render_pass.GetInterface ());
140+
141+ // Populate lazily-initialized attachment texture caches with the original attachments
142+ const Base::Texture* orig_color_texture_ptr = &base_render_pass.GetColorAttachmentTextures ().front ().get ();
143+ const Base::Texture* orig_depth_texture_ptr = base_render_pass.GetDepthAttachmentTexture ();
144+ CHECK (orig_color_texture_ptr == render_pass_resources.frame_buffer_texture .GetInterfacePtr ().get ());
145+ CHECK (orig_depth_texture_ptr == render_pass_resources.depth_stencil_texture .GetInterfacePtr ().get ());
146+
147+ const Test::RenderPassResources new_render_pass_resources = Test::GetRenderPassResources (render_pattern);
148+ CHECK (render_pass.Update (new_render_pass_resources.settings ));
149+
150+ CHECK (&base_render_pass.GetColorAttachmentTextures ().front ().get () ==
151+ new_render_pass_resources.frame_buffer_texture .GetInterfacePtr ().get ());
152+ CHECK (base_render_pass.GetDepthAttachmentTexture () ==
153+ new_render_pass_resources.depth_stencil_texture .GetInterfacePtr ().get ());
154+ }
155+
135156 SECTION (" Release Attachment Textures" )
136157 {
137158 const Rhi::RenderPassSettings& render_pass_settings = render_pass.GetSettings ();
@@ -140,3 +161,50 @@ TEST_CASE("RHI Render Pass Functions", "[rhi][render][pass]")
140161 CHECK (render_pass_settings.attachments .empty ());
141162 }
142163}
164+
165+ TEST_CASE (" RHI Render Pass with Stencil Attachment Functions" , " [rhi][render][pass]" )
166+ {
167+ const Rhi::RenderPattern render_pattern = render_context.CreateRenderPattern (Test::GetRenderPatternSettings (true ));
168+ const Test::RenderPassResources render_pass_resources = Test::GetRenderPassResources (render_pattern);
169+ const Rhi::RenderPass render_pass = render_pattern.CreateRenderPass (render_pass_resources.settings );
170+ const auto & base_render_pass = dynamic_cast <const Base::RenderPass&>(render_pass.GetInterface ());
171+
172+ SECTION (" Get Stencil Attachment Texture" )
173+ {
174+ REQUIRE (render_pass_resources.stencil_texture .IsInitialized ());
175+ CHECK (base_render_pass.GetStencilAttachmentTexture () ==
176+ render_pass_resources.stencil_texture .GetInterfacePtr ().get ());
177+ }
178+
179+ SECTION (" Update Settings Invalidates Stencil Attachment Texture Cache" )
180+ {
181+ // Populate the lazily-initialized stencil attachment texture cache with the original attachment
182+ REQUIRE (base_render_pass.GetStencilAttachmentTexture () ==
183+ render_pass_resources.stencil_texture .GetInterfacePtr ().get ());
184+
185+ const Test::RenderPassResources new_render_pass_resources = Test::GetRenderPassResources (render_pattern);
186+ REQUIRE (new_render_pass_resources.stencil_texture .GetInterfacePtr () !=
187+ render_pass_resources.stencil_texture .GetInterfacePtr ());
188+ CHECK (render_pass.Update (new_render_pass_resources.settings ));
189+
190+ CHECK (base_render_pass.GetStencilAttachmentTexture () ==
191+ new_render_pass_resources.stencil_texture .GetInterfacePtr ().get ());
192+ }
193+
194+ SECTION (" Update Settings Invalidates Non-Frame-Buffer Attachment Textures Cache" )
195+ {
196+ // Frame buffer color attachment is excluded from the non-frame-buffer textures, so only depth & stencil remain
197+ const Ptrs<Base::Texture>& orig_textures = base_render_pass.GetNonFrameBufferAttachmentTextures ();
198+ REQUIRE (orig_textures.size () == 2U );
199+ CHECK (orig_textures[0 ].get () == render_pass_resources.depth_stencil_texture .GetInterfacePtr ().get ());
200+ CHECK (orig_textures[1 ].get () == render_pass_resources.stencil_texture .GetInterfacePtr ().get ());
201+
202+ const Test::RenderPassResources new_render_pass_resources = Test::GetRenderPassResources (render_pattern);
203+ CHECK (render_pass.Update (new_render_pass_resources.settings ));
204+
205+ const Ptrs<Base::Texture>& new_textures = base_render_pass.GetNonFrameBufferAttachmentTextures ();
206+ REQUIRE (new_textures.size () == 2U );
207+ CHECK (new_textures[0 ].get () == new_render_pass_resources.depth_stencil_texture .GetInterfacePtr ().get ());
208+ CHECK (new_textures[1 ].get () == new_render_pass_resources.stencil_texture .GetInterfacePtr ().get ());
209+ }
210+ }
0 commit comments