RenderAttachmentLayoutBuilderTests.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "RHITestFixture.h"
  9. #include <Atom/RHI.Reflect/RenderAttachmentLayoutBuilder.h>
  10. #include <AzCore/Name/NameDictionary.h>
  11. namespace UnitTest
  12. {
  13. using namespace AZ;
  14. using namespace RHI;
  15. class RenderAttachmentLayoutBuilderTests
  16. : public RHITestFixture
  17. {
  18. protected:
  19. template<class T>
  20. void ExpectEqMemory(AZStd::span<const T> expected, AZStd::span<const T> actual)
  21. {
  22. EXPECT_EQ(expected.size(), actual.size());
  23. EXPECT_TRUE(memcmp(expected.data(), actual.data(), expected.size() * sizeof(T)) == 0);
  24. }
  25. void ExpectEq(AZStd::span<const SubpassRenderAttachmentLayout> expected, AZStd::span<const SubpassRenderAttachmentLayout> actual)
  26. {
  27. EXPECT_EQ(expected.size(), actual.size());
  28. for (int i = 0; i < expected.size() && i < actual.size(); ++i)
  29. {
  30. const auto& expectedLayout = expected[i];
  31. const auto& actualLayout = actual[i];
  32. ExpectEqMemory<RenderAttachmentDescriptor>(
  33. { expectedLayout.m_rendertargetDescriptors.begin(), expectedLayout.m_rendertargetCount },
  34. { actualLayout.m_rendertargetDescriptors.begin(), actualLayout.m_rendertargetCount });
  35. ExpectEqMemory<SubpassInputDescriptor>(
  36. { expectedLayout.m_subpassInputDescriptors.begin(), expectedLayout.m_subpassInputCount },
  37. { actualLayout.m_subpassInputDescriptors.begin(), actualLayout.m_subpassInputCount });
  38. ExpectEqMemory<RenderAttachmentDescriptor>({ &expectedLayout.m_depthStencilDescriptor, 1 }, { &actualLayout.m_depthStencilDescriptor, 1 });
  39. }
  40. }
  41. void ExpectEq(const RenderAttachmentLayout& expected, const RenderAttachmentLayout& actual)
  42. {
  43. ExpectEqMemory<Format>({ expected.m_attachmentFormats.begin(), expected.m_attachmentCount }, { actual.m_attachmentFormats.begin(), actual.m_attachmentCount });
  44. ExpectEq({ expected.m_subpassLayouts.begin(), expected.m_subpassCount }, { actual.m_subpassLayouts.begin(), actual.m_subpassCount });
  45. }
  46. };
  47. TEST_F(RenderAttachmentLayoutBuilderTests, TestDefault)
  48. {
  49. RenderAttachmentLayout expected;
  50. RenderAttachmentLayout actual;
  51. ResultCode result = RenderAttachmentLayoutBuilder().End(actual);
  52. EXPECT_EQ(result, ResultCode::Success);
  53. ExpectEq(expected, actual);
  54. }
  55. TEST_F(RenderAttachmentLayoutBuilderTests, TestSingleSubpass)
  56. {
  57. RenderAttachmentLayout expected;
  58. {
  59. expected.m_subpassCount = 1;
  60. expected.m_attachmentCount = 3;
  61. expected.m_attachmentFormats[0] = Format::R16_FLOAT;
  62. expected.m_attachmentFormats[1] = Format::R8G8B8A8_SINT;
  63. expected.m_attachmentFormats[2] = Format::D16_UNORM;
  64. auto& subpassLayout = expected.m_subpassLayouts[0];
  65. subpassLayout.m_rendertargetCount = 2;
  66. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  67. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  68. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 2;
  69. }
  70. RenderAttachmentLayout actual;
  71. {
  72. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  73. layoutBuilder.AddSubpass()
  74. ->RenderTargetAttachment(Format::R16_FLOAT)
  75. ->RenderTargetAttachment(Format::R8G8B8A8_SINT)
  76. ->DepthStencilAttachment(Format::D16_UNORM);
  77. ResultCode result = layoutBuilder.End(actual);
  78. EXPECT_EQ(result, ResultCode::Success);
  79. }
  80. ExpectEq(expected, actual);
  81. }
  82. TEST_F(RenderAttachmentLayoutBuilderTests, TestMultipleSubpasses)
  83. {
  84. RenderAttachmentLayout expected;
  85. {
  86. expected.m_subpassCount = 2;
  87. expected.m_attachmentCount = 4;
  88. expected.m_attachmentFormats[0] = Format::R10G10B10A2_UNORM;
  89. expected.m_attachmentFormats[1] = Format::R32_FLOAT;
  90. expected.m_attachmentFormats[2] = Format::R10G10B10A2_UNORM;
  91. expected.m_attachmentFormats[3] = Format::D24_UNORM_S8_UINT;
  92. {
  93. auto& subpassLayout = expected.m_subpassLayouts[0];
  94. subpassLayout.m_rendertargetCount = 2;
  95. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  96. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  97. }
  98. {
  99. auto& subpassLayout = expected.m_subpassLayouts[1];
  100. subpassLayout.m_rendertargetCount = 1;
  101. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 2;
  102. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 3;
  103. }
  104. }
  105. RenderAttachmentLayout actual;
  106. {
  107. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  108. layoutBuilder.AddSubpass()
  109. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  110. ->RenderTargetAttachment(Format::R32_FLOAT);
  111. layoutBuilder.AddSubpass()
  112. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  113. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  114. ResultCode result = layoutBuilder.End(actual);
  115. EXPECT_EQ(result, ResultCode::Success);
  116. }
  117. ExpectEq(expected, actual);
  118. }
  119. TEST_F(RenderAttachmentLayoutBuilderTests, TestSubpassInputs)
  120. {
  121. RenderAttachmentLayout expected;
  122. {
  123. expected.m_subpassCount = 3;
  124. expected.m_attachmentCount = 4;
  125. expected.m_attachmentFormats[0] = Format::R10G10B10A2_UNORM;
  126. expected.m_attachmentFormats[1] = Format::R32_FLOAT;
  127. expected.m_attachmentFormats[2] = Format::R10G10B10A2_UNORM;
  128. expected.m_attachmentFormats[3] = Format::D24_UNORM_S8_UINT;
  129. {
  130. auto& subpassLayout = expected.m_subpassLayouts[0];
  131. subpassLayout.m_rendertargetCount = 2;
  132. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  133. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  134. }
  135. {
  136. auto& subpassLayout = expected.m_subpassLayouts[1];
  137. subpassLayout.m_rendertargetCount = 1;
  138. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 2;
  139. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 3;
  140. }
  141. {
  142. auto& subpassLayout = expected.m_subpassLayouts[2];
  143. subpassLayout.m_rendertargetCount = 1;
  144. subpassLayout.m_subpassInputCount = 2;
  145. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 1;
  146. subpassLayout.m_subpassInputDescriptors[0] = RHI::SubpassInputDescriptor{ 2, ImageAspectFlags::Color };
  147. subpassLayout.m_subpassInputDescriptors[1] = RHI::SubpassInputDescriptor{ 0, ImageAspectFlags::Color };
  148. }
  149. }
  150. RenderAttachmentLayout actual;
  151. {
  152. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  153. layoutBuilder.AddSubpass()
  154. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM, Name{ "InputAttachment1" })
  155. ->RenderTargetAttachment(Format::R32_FLOAT, Name{ "RenderTarget0" });
  156. layoutBuilder.AddSubpass()
  157. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM, Name{ "InputAttachment0" })
  158. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  159. layoutBuilder.AddSubpass()
  160. ->RenderTargetAttachment(Name{ "RenderTarget0" })
  161. ->SubpassInputAttachment(Name{ "InputAttachment0" }, ImageAspectFlags::Color)
  162. ->SubpassInputAttachment(Name{ "InputAttachment1" }, ImageAspectFlags::Color);
  163. ResultCode result = layoutBuilder.End(actual);
  164. EXPECT_EQ(result, ResultCode::Success);
  165. }
  166. ExpectEq(expected, actual);
  167. }
  168. TEST_F(RenderAttachmentLayoutBuilderTests, TestResolveAttachments)
  169. {
  170. RenderAttachmentLayout expected;
  171. {
  172. expected.m_subpassCount = 1;
  173. expected.m_attachmentCount = 4;
  174. expected.m_attachmentFormats[0] = Format::R16_FLOAT;
  175. expected.m_attachmentFormats[1] = Format::R16_FLOAT;
  176. expected.m_attachmentFormats[2] = Format::R8G8B8A8_SINT;
  177. expected.m_attachmentFormats[3] = Format::D16_UNORM;
  178. auto& subpassLayout = expected.m_subpassLayouts[0];
  179. subpassLayout.m_rendertargetCount = 2;
  180. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 1;
  181. subpassLayout.m_rendertargetDescriptors[0].m_resolveAttachmentIndex = 0;
  182. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 2;
  183. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 3;
  184. }
  185. RenderAttachmentLayout actual;
  186. {
  187. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  188. layoutBuilder.AddSubpass()
  189. ->RenderTargetAttachment(Format::R16_FLOAT, true)
  190. ->RenderTargetAttachment(Format::R8G8B8A8_SINT)
  191. ->DepthStencilAttachment(Format::D16_UNORM);
  192. ResultCode result = layoutBuilder.End(actual);
  193. EXPECT_EQ(result, ResultCode::Success);
  194. }
  195. ExpectEq(expected, actual);
  196. }
  197. TEST_F(RenderAttachmentLayoutBuilderTests, TestRenderTargetByName)
  198. {
  199. RenderAttachmentLayout expected;
  200. {
  201. expected.m_subpassCount = 2;
  202. expected.m_attachmentCount = 3;
  203. expected.m_attachmentFormats[0] = Format::R16_FLOAT;
  204. expected.m_attachmentFormats[1] = Format::R8G8B8A8_SINT;
  205. expected.m_attachmentFormats[2] = Format::D16_UNORM;
  206. {
  207. auto& subpassLayout = expected.m_subpassLayouts[0];
  208. subpassLayout.m_rendertargetCount = 2;
  209. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  210. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  211. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 2;
  212. }
  213. {
  214. auto& subpassLayout = expected.m_subpassLayouts[1];
  215. subpassLayout.m_rendertargetCount = 2;
  216. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  217. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  218. }
  219. }
  220. RenderAttachmentLayout actual;
  221. {
  222. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  223. layoutBuilder.AddSubpass()
  224. ->RenderTargetAttachment(Format::R16_FLOAT, Name{ "RenderTaret0" })
  225. ->RenderTargetAttachment(Format::R8G8B8A8_SINT, Name{ "RenderTaret1" })
  226. ->DepthStencilAttachment(Format::D16_UNORM);
  227. layoutBuilder.AddSubpass()
  228. ->RenderTargetAttachment(Name{ "RenderTaret0" })
  229. ->RenderTargetAttachment(Name{ "RenderTaret1" });
  230. ResultCode result = layoutBuilder.End(actual);
  231. EXPECT_EQ(result, ResultCode::Success);
  232. }
  233. ExpectEq(expected, actual);
  234. }
  235. TEST_F(RenderAttachmentLayoutBuilderTests, TestDepthStencil)
  236. {
  237. RenderAttachmentLayout expected;
  238. {
  239. expected.m_subpassCount = 2;
  240. expected.m_attachmentCount = 3;
  241. expected.m_attachmentFormats[0] = Format::R16_FLOAT;
  242. expected.m_attachmentFormats[1] = Format::R8G8B8A8_SINT;
  243. expected.m_attachmentFormats[2] = Format::D16_UNORM;
  244. {
  245. auto& subpassLayout = expected.m_subpassLayouts[0];
  246. subpassLayout.m_rendertargetCount = 2;
  247. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  248. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  249. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 2;
  250. }
  251. {
  252. auto& subpassLayout = expected.m_subpassLayouts[1];
  253. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 2;
  254. }
  255. }
  256. RenderAttachmentLayout actual;
  257. {
  258. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  259. layoutBuilder.AddSubpass()
  260. ->RenderTargetAttachment(Format::R16_FLOAT)
  261. ->RenderTargetAttachment(Format::R8G8B8A8_SINT)
  262. ->DepthStencilAttachment(Format::D16_UNORM);
  263. layoutBuilder.AddSubpass()
  264. ->DepthStencilAttachment();
  265. ResultCode result = layoutBuilder.End(actual);
  266. EXPECT_EQ(result, ResultCode::Success);
  267. }
  268. ExpectEq(expected, actual);
  269. }
  270. TEST_F(RenderAttachmentLayoutBuilderTests, TestResolveByName)
  271. {
  272. RenderAttachmentLayout expected;
  273. {
  274. expected.m_subpassCount = 1;
  275. expected.m_attachmentCount = 4;
  276. expected.m_attachmentFormats[0] = Format::R16_FLOAT;
  277. expected.m_attachmentFormats[1] = Format::R16_FLOAT;
  278. expected.m_attachmentFormats[2] = Format::R8G8B8A8_SINT;
  279. expected.m_attachmentFormats[3] = Format::D16_UNORM;
  280. auto& subpassLayout = expected.m_subpassLayouts[0];
  281. subpassLayout.m_rendertargetCount = 2;
  282. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 1;
  283. subpassLayout.m_rendertargetDescriptors[0].m_resolveAttachmentIndex = 0;
  284. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 2;
  285. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 3;
  286. }
  287. RenderAttachmentLayout actual;
  288. {
  289. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  290. layoutBuilder.AddSubpass()
  291. ->RenderTargetAttachment(Format::R16_FLOAT, Name{ "RenderTarget0" })
  292. ->RenderTargetAttachment(Format::R8G8B8A8_SINT)
  293. ->DepthStencilAttachment(Format::D16_UNORM)
  294. ->ResolveAttachment(Name{ "RenderTarget0" });
  295. ResultCode result = layoutBuilder.End(actual);
  296. EXPECT_EQ(result, ResultCode::Success);
  297. }
  298. ExpectEq(expected, actual);
  299. }
  300. TEST_F(RenderAttachmentLayoutBuilderTests, TestResolveAsSubpassInput)
  301. {
  302. RenderAttachmentLayout expected;
  303. {
  304. expected.m_subpassCount = 2;
  305. expected.m_attachmentCount = 4;
  306. expected.m_attachmentFormats[0] = Format::R10G10B10A2_UNORM;
  307. expected.m_attachmentFormats[1] = Format::R10G10B10A2_UNORM;
  308. expected.m_attachmentFormats[2] = Format::R32_FLOAT;
  309. expected.m_attachmentFormats[3] = Format::D24_UNORM_S8_UINT;
  310. {
  311. auto& subpassLayout = expected.m_subpassLayouts[0];
  312. subpassLayout.m_rendertargetCount = 2;
  313. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 1;
  314. subpassLayout.m_rendertargetDescriptors[0].m_resolveAttachmentIndex = 0;
  315. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 2;
  316. }
  317. {
  318. auto& subpassLayout = expected.m_subpassLayouts[1];
  319. subpassLayout.m_subpassInputCount = 1;
  320. subpassLayout.m_subpassInputDescriptors[0] = RHI::SubpassInputDescriptor{ 0, ImageAspectFlags::Color };
  321. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 3;
  322. }
  323. }
  324. RenderAttachmentLayout actual;
  325. {
  326. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  327. layoutBuilder.AddSubpass()
  328. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM, Name{ "ColorAttachment0" })
  329. ->RenderTargetAttachment(Format::R32_FLOAT)
  330. ->ResolveAttachment(Name{ "ColorAttachment0" }, Name{ "Resolve0" });
  331. layoutBuilder.AddSubpass()
  332. ->SubpassInputAttachment(Name{ "Resolve0" }, ImageAspectFlags::Color)
  333. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  334. ResultCode result = layoutBuilder.End(actual);
  335. EXPECT_EQ(result, ResultCode::Success);
  336. }
  337. ExpectEq(expected, actual);
  338. }
  339. TEST_F(RenderAttachmentLayoutBuilderTests, TestAttachmentLoadStoreAction)
  340. {
  341. RenderAttachmentLayout expected;
  342. AttachmentLoadStoreAction renderTargetLoadStoreAction;
  343. renderTargetLoadStoreAction.m_storeAction = RHI::AttachmentStoreAction::DontCare;
  344. AttachmentLoadStoreAction depthStencilLoadStoreAction;
  345. {
  346. expected.m_subpassCount = 1;
  347. expected.m_attachmentCount = 3;
  348. expected.m_attachmentFormats[0] = Format::R10G10B10A2_UNORM;
  349. expected.m_attachmentFormats[1] = Format::R32_FLOAT;
  350. expected.m_attachmentFormats[2] = Format::D24_UNORM_S8_UINT;
  351. {
  352. auto& subpassLayout = expected.m_subpassLayouts[0];
  353. subpassLayout.m_rendertargetCount = 2;
  354. subpassLayout.m_rendertargetDescriptors[0].m_attachmentIndex = 0;
  355. subpassLayout.m_rendertargetDescriptors[0].m_loadStoreAction = renderTargetLoadStoreAction;
  356. subpassLayout.m_rendertargetDescriptors[1].m_attachmentIndex = 1;
  357. subpassLayout.m_rendertargetDescriptors[1].m_loadStoreAction = depthStencilLoadStoreAction;
  358. subpassLayout.m_depthStencilDescriptor.m_attachmentIndex = 2;
  359. }
  360. }
  361. RenderAttachmentLayout actual;
  362. {
  363. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  364. depthStencilLoadStoreAction.m_storeActionStencil = RHI::AttachmentStoreAction::Store;
  365. layoutBuilder.AddSubpass()
  366. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM, Name{"RenderTarget0"}, renderTargetLoadStoreAction)
  367. ->RenderTargetAttachment(Format::R32_FLOAT)
  368. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT, Name{ "DepthStencil" }, depthStencilLoadStoreAction);
  369. ResultCode result = layoutBuilder.End(actual);
  370. EXPECT_EQ(result, ResultCode::Success);
  371. }
  372. ExpectEq(expected, actual);
  373. }
  374. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidRenderTargetFormat)
  375. {
  376. RenderAttachmentLayout actual;
  377. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  378. layoutBuilder.AddSubpass()
  379. ->RenderTargetAttachment(Format::Unknown)
  380. ->RenderTargetAttachment(Format::R32_FLOAT)
  381. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  382. AZ_TEST_START_TRACE_SUPPRESSION;
  383. ResultCode result = layoutBuilder.End(actual);
  384. EXPECT_EQ(result, ResultCode::InvalidArgument);
  385. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  386. }
  387. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidRenderTargetFormatByReference)
  388. {
  389. RenderAttachmentLayout actual;
  390. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  391. layoutBuilder.AddSubpass()
  392. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM, Name{ "RenderAttachment0" })
  393. ->RenderTargetAttachment(Format::R32_FLOAT)
  394. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  395. layoutBuilder.AddSubpass()
  396. ->RenderTargetAttachment(Format::R32_FLOAT, Name{ "RenderAttachment0" });
  397. AZ_TEST_START_TRACE_SUPPRESSION;
  398. ResultCode result = layoutBuilder.End(actual);
  399. EXPECT_EQ(result, ResultCode::InvalidArgument);
  400. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  401. }
  402. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidRenderTargetName)
  403. {
  404. RenderAttachmentLayout actual;
  405. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  406. layoutBuilder.AddSubpass()
  407. ->RenderTargetAttachment(Name{ "RenderAttachment0" })
  408. ->RenderTargetAttachment(Format::R32_FLOAT)
  409. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  410. AZ_TEST_START_TRACE_SUPPRESSION;
  411. ResultCode result = layoutBuilder.End(actual);
  412. EXPECT_EQ(result, ResultCode::InvalidArgument);
  413. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  414. }
  415. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidDepthStencilFormat)
  416. {
  417. RenderAttachmentLayout actual;
  418. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  419. layoutBuilder.AddSubpass()
  420. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  421. ->RenderTargetAttachment(Format::R32_FLOAT)
  422. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT);
  423. layoutBuilder.AddSubpass()
  424. ->DepthStencilAttachment(Format::D32_FLOAT);
  425. AZ_TEST_START_TRACE_SUPPRESSION;
  426. ResultCode result = layoutBuilder.End(actual);
  427. EXPECT_EQ(result, ResultCode::InvalidArgument);
  428. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  429. }
  430. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidDepthStencilName)
  431. {
  432. RenderAttachmentLayout actual;
  433. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  434. layoutBuilder.AddSubpass()
  435. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  436. ->RenderTargetAttachment(Format::R32_FLOAT)
  437. ->DepthStencilAttachment(Format::D24_UNORM_S8_UINT, Name{ "DepthStencil" });
  438. layoutBuilder.AddSubpass()
  439. ->DepthStencilAttachment(Name{ "InvalidDepthStencilName" });
  440. AZ_TEST_START_TRACE_SUPPRESSION;
  441. ResultCode result = layoutBuilder.End(actual);
  442. EXPECT_EQ(result, ResultCode::InvalidArgument);
  443. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  444. }
  445. TEST_F(RenderAttachmentLayoutBuilderTests, TestNotDefinedDepthStencilFormat)
  446. {
  447. RenderAttachmentLayout actual;
  448. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  449. layoutBuilder.AddSubpass()
  450. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  451. ->RenderTargetAttachment(Format::R32_FLOAT)
  452. ->DepthStencilAttachment();
  453. AZ_TEST_START_TRACE_SUPPRESSION;
  454. ResultCode result = layoutBuilder.End(actual);
  455. EXPECT_EQ(result, ResultCode::InvalidArgument);
  456. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  457. }
  458. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidResolve)
  459. {
  460. RenderAttachmentLayout actual;
  461. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  462. AZ_TEST_START_TRACE_SUPPRESSION;
  463. layoutBuilder.AddSubpass()
  464. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  465. ->RenderTargetAttachment(Format::R32_FLOAT)
  466. ->ResolveAttachment(Name{ "InvalidAttachment" });
  467. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  468. }
  469. TEST_F(RenderAttachmentLayoutBuilderTests, TestInvalidSubpassInput)
  470. {
  471. RenderAttachmentLayout actual;
  472. RHI::RenderAttachmentLayoutBuilder layoutBuilder;
  473. layoutBuilder.AddSubpass()
  474. ->RenderTargetAttachment(Format::R10G10B10A2_UNORM)
  475. ->RenderTargetAttachment(Format::R32_FLOAT);
  476. layoutBuilder.AddSubpass()->SubpassInputAttachment(Name{ "InvalidSubpassInput" }, ImageAspectFlags::Color);
  477. AZ_TEST_START_TRACE_SUPPRESSION;
  478. ResultCode result = layoutBuilder.End(actual);
  479. EXPECT_EQ(result, ResultCode::InvalidArgument);
  480. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  481. }
  482. }