MSAAExampleComponent.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 <Atom/RHI/CommandList.h>
  9. #include <Atom/RPI.Public/Shader/Shader.h>
  10. #include <Atom/RHI.Reflect/InputStreamLayoutBuilder.h>
  11. #include <Atom/RHI.Reflect/RenderAttachmentLayoutBuilder.h>
  12. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  13. #include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
  14. #include <AzCore/Serialization/SerializeContext.h>
  15. #include <AzCore/std/createdestroy.h>
  16. #include <RHI/MSAAExampleComponent.h>
  17. #include <SampleComponentManager.h>
  18. #include <Utils/Utils.h>
  19. namespace AtomSampleViewer
  20. {
  21. namespace
  22. {
  23. const char* TriangeShaderFilePath = "Shaders/RHI/triangle.azshader";
  24. const char* CustomResolveShaderFilePath = "Shaders/RHI/MSAAResolve.azshader";
  25. const char* SampleName = "MSAAExample";
  26. }
  27. void MSAAExampleComponent::Reflect(AZ::ReflectContext* context)
  28. {
  29. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  30. {
  31. serializeContext->Class<MSAAExampleComponent, AZ::Component>()
  32. ->Version(0)
  33. ;
  34. }
  35. }
  36. MSAAExampleComponent::MSAAExampleComponent()
  37. {
  38. m_supportRHISamplePipeline = true;
  39. }
  40. void MSAAExampleComponent::Activate()
  41. {
  42. using namespace AZ;
  43. RHI::Ptr<RHI::Device> device = Utils::GetRHIDevice();
  44. m_inputAssemblyBufferPool = RHI::Factory::Get().CreateBufferPool();
  45. RHI::BufferPoolDescriptor bufferPoolDesc;
  46. bufferPoolDesc.m_bindFlags = RHI::BufferBindFlags::InputAssembly;
  47. bufferPoolDesc.m_heapMemoryLevel = RHI::HeapMemoryLevel::Device;
  48. m_inputAssemblyBufferPool->Init(*device, bufferPoolDesc);
  49. AZStd::vector<RHI::SamplePosition> emptySamplePositions;
  50. AZStd::vector<RHI::SamplePosition> customSamplePositions = { RHI::SamplePosition(3, 3), RHI::SamplePosition(11, 3), RHI::SamplePosition(3, 11), RHI::SamplePosition(11, 11) };
  51. m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA2X)] = { 2, true, emptySamplePositions, RHI::AttachmentStoreAction::DontCare, RHI::AttachmentId("MSAA2X"), true };
  52. m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA4X)] = { 4, true, emptySamplePositions, RHI::AttachmentStoreAction::DontCare, RHI::AttachmentId("MSAA4X"), true };
  53. m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA4X_Custom_Positions)] = { 4, true, customSamplePositions, RHI::AttachmentStoreAction::DontCare, RHI::AttachmentId("MSAA4X_Custom_Positions"), true };
  54. m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA4X_Custom_Resolve)] = { 4, false, emptySamplePositions, RHI::AttachmentStoreAction::Store, RHI::AttachmentId("MSAA4X_Custom_Resolve"), true };
  55. m_sampleProperties[static_cast<uint32_t>(MSAAType::NoAA)] = { 1, false, emptySamplePositions, RHI::AttachmentStoreAction::Store, m_outputAttachmentId, false };
  56. CreateTriangleResources();
  57. CreateQuadResources();
  58. for (uint32_t i = 0; i < s_numMSAAExamples; ++i)
  59. {
  60. auto msaaType = static_cast<MSAAType>(i);
  61. CreateScopeResources(msaaType);
  62. CreateScopeProducer(msaaType);
  63. }
  64. // Extra scopes for resolving the MSAA texture using a custom shader
  65. CreateCustomMSAAResolveResources();
  66. CreateCustomMSAAResolveScope();
  67. OnMSAATypeChanged(m_currentType);
  68. AZ::RHI::RHISystemNotificationBus::Handler::BusConnect();
  69. AzFramework::InputChannelEventListener::Connect();
  70. }
  71. void MSAAExampleComponent::Deactivate()
  72. {
  73. m_triangleInputAssemblyBuffer = nullptr;
  74. m_quadInputAssemblyBuffer = nullptr;
  75. m_inputAssemblyBufferPool = nullptr;
  76. m_pipelineStates.fill(nullptr);
  77. m_customResolveMSAAPipelineState = nullptr;
  78. m_triangleShaderResourceGroup = nullptr;
  79. m_customMSAAResolveShaderResourceGroup = nullptr;
  80. AzFramework::InputChannelEventListener::Disconnect();
  81. AZ::RHI::RHISystemNotificationBus::Handler::BusDisconnect();
  82. m_windowContext = nullptr;
  83. AZStd::for_each(m_MSAAScopeProducers.begin(), m_MSAAScopeProducers.end(), [](auto& list) { list.clear(); });
  84. m_scopeProducers.clear();
  85. }
  86. bool MSAAExampleComponent::OnInputChannelEventFiltered(const AzFramework::InputChannel & inputChannel)
  87. {
  88. const AzFramework::InputChannelId& inputChannelId = inputChannel.GetInputChannelId();
  89. switch (inputChannel.GetState())
  90. {
  91. case AzFramework::InputChannel::State::Ended:
  92. {
  93. if (inputChannelId == AzFramework::InputDeviceMouse::Button::Left)
  94. {
  95. OnMSAATypeChanged(static_cast<MSAAType>((static_cast<uint32_t>(m_currentType) + 1) % s_numMSAAExamples));
  96. }
  97. }
  98. default:
  99. {
  100. break;
  101. }
  102. }
  103. return false;
  104. }
  105. void MSAAExampleComponent::CreateTriangleResources()
  106. {
  107. using namespace AZ;
  108. TriangleBufferData bufferData;
  109. SetVertexPosition(bufferData.m_positions.data(), 0, 0.0, 0.5, 0.0);
  110. SetVertexPosition(bufferData.m_positions.data(), 1, -0.5, -0.5, 0.0);
  111. SetVertexPosition(bufferData.m_positions.data(), 2, 0.5, -0.5, 0.0);
  112. SetVertexColor(bufferData.m_colors.data(), 0, 1.0, 0.0, 0.0, 1.0);
  113. SetVertexColor(bufferData.m_colors.data(), 1, 0.0, 1.0, 0.0, 1.0);
  114. SetVertexColor(bufferData.m_colors.data(), 2, 0.0, 0.0, 1.0, 1.0);
  115. SetVertexIndexIncreasing(bufferData.m_indices.data(), bufferData.m_indices.size());
  116. m_triangleInputAssemblyBuffer = RHI::Factory::Get().CreateBuffer();
  117. RHI::BufferInitRequest request;
  118. request.m_buffer = m_triangleInputAssemblyBuffer.get();
  119. request.m_descriptor = RHI::BufferDescriptor{ RHI::BufferBindFlags::InputAssembly, sizeof(bufferData) };
  120. request.m_initialData = &bufferData;
  121. m_inputAssemblyBufferPool->InitBuffer(request);
  122. m_triangleStreamBufferViews[0] =
  123. {
  124. *m_triangleInputAssemblyBuffer,
  125. offsetof(TriangleBufferData, m_positions),
  126. sizeof(TriangleBufferData::m_positions),
  127. sizeof(VertexPosition)
  128. };
  129. m_triangleStreamBufferViews[1] =
  130. {
  131. *m_triangleInputAssemblyBuffer,
  132. offsetof(TriangleBufferData, m_colors),
  133. sizeof(TriangleBufferData::m_colors),
  134. sizeof(VertexColor)
  135. };
  136. RHI::InputStreamLayoutBuilder layoutBuilder;
  137. layoutBuilder.AddBuffer()->Channel("POSITION", RHI::Format::R32G32B32_FLOAT);
  138. layoutBuilder.AddBuffer()->Channel("COLOR", RHI::Format::R32G32B32A32_FLOAT);
  139. m_triangleInputStreamLayout = layoutBuilder.End();
  140. RHI::ValidateStreamBufferViews(m_triangleInputStreamLayout, m_triangleStreamBufferViews);
  141. m_triangleShader = LoadShader(TriangeShaderFilePath, SampleName);
  142. if (!m_triangleShader)
  143. {
  144. return;
  145. }
  146. m_triangleShaderResourceGroup = CreateShaderResourceGroup(m_triangleShader, "TriangleInstanceSrg", SampleName);
  147. const Name objectMatrixConstantId{ "m_objectMatrix" };
  148. FindShaderInputIndex(&m_objectMatrixConstantIndex, m_triangleShaderResourceGroup, objectMatrixConstantId, SampleName);
  149. [[maybe_unused]] bool success = m_triangleShaderResourceGroup->SetConstant(m_objectMatrixConstantIndex, AZ::Matrix4x4::CreateIdentity());
  150. AZ_Warning("MSAAExampleComponent", success, "Failed to set SRG Constant m_objectMatrix");
  151. m_triangleShaderResourceGroup->Compile();
  152. }
  153. void MSAAExampleComponent::CreateQuadResources()
  154. {
  155. using namespace AZ;
  156. QuadBufferData bufferData;
  157. SetFullScreenRect(bufferData.m_positions.data(), bufferData.m_uvs.data(), bufferData.m_indices.data());
  158. m_quadInputAssemblyBuffer = RHI::Factory::Get().CreateBuffer();
  159. RHI::ResultCode result = RHI::ResultCode::Success;
  160. RHI::BufferInitRequest request;
  161. request.m_buffer = m_quadInputAssemblyBuffer.get();
  162. request.m_descriptor = RHI::BufferDescriptor{ RHI::BufferBindFlags::InputAssembly, sizeof(bufferData) };
  163. request.m_initialData = &bufferData;
  164. result = m_inputAssemblyBufferPool->InitBuffer(request);
  165. if (result != RHI::ResultCode::Success)
  166. {
  167. AZ_Error(SampleName, false, "Failed to initialize position buffer with error code %d", result);
  168. return;
  169. }
  170. m_quadStreamBufferViews[0] = {
  171. *m_quadInputAssemblyBuffer,
  172. offsetof(QuadBufferData, m_positions),
  173. sizeof(QuadBufferData::m_positions),
  174. sizeof(VertexPosition)
  175. };
  176. m_quadStreamBufferViews[1] = {
  177. *m_quadInputAssemblyBuffer,
  178. offsetof(QuadBufferData, m_uvs),
  179. sizeof(QuadBufferData::m_uvs),
  180. sizeof(VertexUV)
  181. };
  182. RHI::InputStreamLayoutBuilder layoutBuilder;
  183. layoutBuilder.AddBuffer()->Channel("POSITION", RHI::Format::R32G32B32_FLOAT);
  184. layoutBuilder.AddBuffer()->Channel("UV", RHI::Format::R32G32_FLOAT);
  185. m_quadInputStreamLayout = layoutBuilder.End();
  186. RHI::ValidateStreamBufferViews(m_quadInputStreamLayout, m_quadStreamBufferViews);
  187. m_customMSAAResolveShader = LoadShader(CustomResolveShaderFilePath, SampleName);
  188. if (!m_customMSAAResolveShader)
  189. {
  190. return;
  191. }
  192. m_customMSAAResolveShaderResourceGroup = CreateShaderResourceGroup(m_customMSAAResolveShader, "TextureInstanceSrg", SampleName);
  193. const Name albedoMapId{ "m_albedoMap" };
  194. FindShaderInputIndex(&m_customMSAAResolveTextureInputIndex, m_customMSAAResolveShaderResourceGroup, albedoMapId, SampleName);
  195. }
  196. void MSAAExampleComponent::OnMSAATypeChanged(MSAAType type)
  197. {
  198. auto msaaTypeIndex = static_cast<uint32_t>(type);
  199. m_scopeProducers.clear();
  200. m_scopeProducers.insert(m_scopeProducers.end(), m_MSAAScopeProducers[msaaTypeIndex].begin(), m_MSAAScopeProducers[msaaTypeIndex].end());
  201. m_currentType = type;
  202. }
  203. void MSAAExampleComponent::CreateScopeResources(MSAAType type)
  204. {
  205. using namespace AZ;
  206. const auto& properties = m_sampleProperties[static_cast<uint32_t>(type)];
  207. AZ::RHI::PipelineStateDescriptorForDraw pipelineStateDescriptor;
  208. pipelineStateDescriptor.m_inputStreamLayout = m_triangleInputStreamLayout;
  209. auto shaderVariant = m_triangleShader->GetVariant(RPI::ShaderAsset::RootShaderVariantStableId);
  210. shaderVariant.ConfigurePipelineState(pipelineStateDescriptor);
  211. RHI::RenderAttachmentLayoutBuilder attachmentsBuilder;
  212. attachmentsBuilder.AddSubpass()
  213. ->RenderTargetAttachment(m_outputFormat, properties.m_resolve);
  214. [[maybe_unused]] RHI::ResultCode result = attachmentsBuilder.End(pipelineStateDescriptor.m_renderAttachmentConfiguration.m_renderAttachmentLayout);
  215. AZ_Assert(result == RHI::ResultCode::Success, "Failed to create render attachment layout");
  216. pipelineStateDescriptor.m_renderStates.m_multisampleState.m_samples = static_cast<uint16_t>(properties.m_samplesCount);
  217. auto& customPositionList = pipelineStateDescriptor.m_renderStates.m_multisampleState.m_customPositions;
  218. AZStd::copy(properties.m_customPositions.begin(), properties.m_customPositions.end(), customPositionList.begin());
  219. pipelineStateDescriptor.m_renderStates.m_multisampleState.m_customPositionsCount = static_cast<uint32_t>(properties.m_customPositions.size());
  220. auto& pipeline = m_pipelineStates[static_cast<uint32_t>(type)];
  221. pipeline = m_triangleShader->AcquirePipelineState(pipelineStateDescriptor);
  222. if (!pipeline)
  223. {
  224. AZ_Error(SampleName, false, "Failed to acquire default pipeline state for shader '%s'", TriangeShaderFilePath);
  225. return;
  226. }
  227. }
  228. void MSAAExampleComponent::CreateScopeProducer(MSAAType type)
  229. {
  230. using namespace AZ;
  231. uint32_t msaaTypeIndex = static_cast<uint32_t>(type);
  232. // Creates a scope for rendering the triangle.
  233. const auto prepareFunction = [this, msaaTypeIndex](RHI::FrameGraphInterface frameGraph, [[maybe_unused]] ScopeData& scopeData)
  234. {
  235. {
  236. // Binds the MSAA color attachment.
  237. RHI::ImageScopeAttachmentDescriptor descriptor;
  238. descriptor.m_attachmentId = m_sampleProperties[msaaTypeIndex].m_attachmentId;
  239. descriptor.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateVector4Float(1.0f, 1.0, 1.0, 0.0);
  240. descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
  241. descriptor.m_loadStoreAction.m_storeAction = m_sampleProperties[msaaTypeIndex].m_storeAction;
  242. if (m_sampleProperties[msaaTypeIndex].m_isTransient)
  243. {
  244. auto imageDesc = RHI::ImageDescriptor::Create2D(
  245. RHI::ImageBindFlags::Color | RHI::ImageBindFlags::ShaderRead,
  246. m_outputWidth,
  247. m_outputHeight,
  248. m_outputFormat);
  249. imageDesc.m_multisampleState = RHI::MultisampleState(static_cast<uint16_t>(m_sampleProperties[msaaTypeIndex].m_samplesCount), 0);
  250. if(m_sampleProperties[msaaTypeIndex].m_customPositions.size()>0)
  251. {
  252. imageDesc.m_multisampleState.m_customPositionsCount = static_cast<uint32_t>(m_sampleProperties[msaaTypeIndex].m_customPositions.size());
  253. auto& customPositionList = imageDesc.m_multisampleState.m_customPositions;
  254. AZStd::copy(m_sampleProperties[msaaTypeIndex].m_customPositions.begin(), m_sampleProperties[msaaTypeIndex].m_customPositions.end(), customPositionList.begin());
  255. }
  256. frameGraph.GetAttachmentDatabase().CreateTransientImage(RHI::TransientImageDescriptor(descriptor.m_attachmentId, imageDesc));
  257. }
  258. frameGraph.UseColorAttachment(descriptor);
  259. }
  260. // Binds the resolve color attachment.
  261. if (m_sampleProperties[msaaTypeIndex].m_resolve)
  262. {
  263. RHI::ResolveScopeAttachmentDescriptor descriptor;
  264. descriptor.m_attachmentId = m_outputAttachmentId;
  265. descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::DontCare;
  266. descriptor.m_resolveAttachmentId = m_sampleProperties[msaaTypeIndex].m_attachmentId;
  267. frameGraph.UseResolveAttachment(descriptor);
  268. }
  269. // We will submit a single draw item.
  270. frameGraph.SetEstimatedItemCount(1);
  271. };
  272. using namespace AZ;
  273. RHI::EmptyCompileFunction<ScopeData> compileFunction;
  274. const auto executeFunction = [this, msaaTypeIndex](const RHI::FrameGraphExecuteContext& context, [[maybe_unused]] const ScopeData& scopeData)
  275. {
  276. RHI::CommandList* commandList = context.GetCommandList();
  277. // Set persistent viewport and scissor state.
  278. commandList->SetViewports(&m_viewport, 1);
  279. commandList->SetScissors(&m_scissor, 1);
  280. const RHI::IndexBufferView indexBufferView =
  281. {
  282. *m_triangleInputAssemblyBuffer,
  283. offsetof(TriangleBufferData, m_indices),
  284. sizeof(TriangleBufferData::m_indices),
  285. RHI::IndexFormat::Uint16
  286. };
  287. RHI::DrawIndexed drawIndexed;
  288. drawIndexed.m_indexCount = 3;
  289. drawIndexed.m_instanceCount = 1;
  290. const RHI::ShaderResourceGroup* shaderResourceGroups[] = { m_triangleShaderResourceGroup->GetRHIShaderResourceGroup() };
  291. RHI::DrawItem drawItem;
  292. drawItem.m_arguments = drawIndexed;
  293. drawItem.m_pipelineState = m_pipelineStates[msaaTypeIndex].get();
  294. drawItem.m_indexBufferView = &indexBufferView;
  295. drawItem.m_shaderResourceGroupCount = static_cast<uint8_t>(RHI::ArraySize(shaderResourceGroups));
  296. drawItem.m_shaderResourceGroups = shaderResourceGroups;
  297. drawItem.m_streamBufferViewCount = static_cast<uint8_t>(m_triangleStreamBufferViews.size());
  298. drawItem.m_streamBufferViews = m_triangleStreamBufferViews.data();
  299. // Submit the triangle draw item.
  300. commandList->Submit(drawItem);
  301. };
  302. auto name = AZStd::string::format("MSAAType_%d", msaaTypeIndex);
  303. const AZ::RHI::ScopeId TriangleScope(name);
  304. m_MSAAScopeProducers[msaaTypeIndex].emplace_back(
  305. aznew RHI::ScopeProducerFunction<
  306. ScopeData,
  307. decltype(prepareFunction),
  308. decltype(compileFunction),
  309. decltype(executeFunction)>(
  310. TriangleScope,
  311. ScopeData{},
  312. prepareFunction,
  313. compileFunction,
  314. executeFunction));
  315. }
  316. void MSAAExampleComponent::CreateCustomMSAAResolveResources()
  317. {
  318. using namespace AZ;
  319. AZ::RHI::PipelineStateDescriptorForDraw pipelineStateDescriptor;
  320. pipelineStateDescriptor.m_inputStreamLayout = m_quadInputStreamLayout;
  321. if (!m_customMSAAResolveShader)
  322. {
  323. return;
  324. }
  325. auto shaderVariant = m_customMSAAResolveShader->GetVariant(AZ::RPI::ShaderAsset::RootShaderVariantStableId);
  326. shaderVariant.ConfigurePipelineState(pipelineStateDescriptor);
  327. RHI::RenderAttachmentLayoutBuilder attachmentsBuilder;
  328. attachmentsBuilder.AddSubpass()
  329. ->RenderTargetAttachment(m_outputFormat);
  330. [[maybe_unused]] RHI::ResultCode result = attachmentsBuilder.End(pipelineStateDescriptor.m_renderAttachmentConfiguration.m_renderAttachmentLayout);
  331. AZ_Assert(result == RHI::ResultCode::Success, "Failed to create render attachment layout");
  332. m_customResolveMSAAPipelineState = m_customMSAAResolveShader->AcquirePipelineState(pipelineStateDescriptor);
  333. if (!m_customResolveMSAAPipelineState)
  334. {
  335. AZ_Error(SampleName, false, "Failed to acquire default pipeline state for shader '%s'", CustomResolveShaderFilePath);
  336. return;
  337. }
  338. }
  339. void MSAAExampleComponent::CreateCustomMSAAResolveScope()
  340. {
  341. using namespace AZ;
  342. const RHI::Ptr<RHI::Device> device = Utils::GetRHIDevice();
  343. const auto prepareFunction = [this](RHI::FrameGraphInterface frameGraph, [[maybe_unused]] const ScopeData& scopeData)
  344. {
  345. // Bind MSAA as a texture attachment to sample
  346. {
  347. RHI::ImageScopeAttachmentDescriptor descriptor;
  348. descriptor.m_attachmentId = m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA4X_Custom_Resolve)].m_attachmentId;
  349. descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
  350. frameGraph.UseShaderAttachment(descriptor, RHI::ScopeAttachmentAccess::Read);
  351. }
  352. // Binds the swap chain as a color attachment.
  353. {
  354. RHI::ImageScopeAttachmentDescriptor descriptor;
  355. descriptor.m_attachmentId = m_outputAttachmentId;
  356. descriptor.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateVector4Float(1.0f, 1.0, 1.0, 0.0);
  357. descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
  358. frameGraph.UseColorAttachment(descriptor);
  359. }
  360. // We will submit a single draw item.
  361. frameGraph.SetEstimatedItemCount(1);
  362. };
  363. const auto compileFunction = [this](const AZ::RHI::FrameGraphCompileContext& context, [[maybe_unused]] const ScopeData& scopeData)
  364. {
  365. const AZ::RHI::ImageView* imageView = context.GetImageView(m_sampleProperties[static_cast<uint32_t>(MSAAType::MSAA4X_Custom_Resolve)].m_attachmentId);
  366. m_customMSAAResolveShaderResourceGroup->SetImageView(m_customMSAAResolveTextureInputIndex, imageView);
  367. m_customMSAAResolveShaderResourceGroup->Compile();
  368. };
  369. const auto executeFunction = [this](const RHI::FrameGraphExecuteContext& context, [[maybe_unused]] const ScopeData& scopeData)
  370. {
  371. RHI::CommandList* commandList = context.GetCommandList();
  372. // Set persistent viewport and scissor state.
  373. commandList->SetViewports(&m_viewport, 1);
  374. commandList->SetScissors(&m_scissor, 1);
  375. const RHI::IndexBufferView indexBufferView =
  376. {
  377. *m_quadInputAssemblyBuffer,
  378. offsetof(QuadBufferData, m_indices),
  379. sizeof(QuadBufferData::m_indices),
  380. RHI::IndexFormat::Uint16
  381. };
  382. RHI::DrawIndexed drawIndexed;
  383. drawIndexed.m_indexCount = 6;
  384. drawIndexed.m_instanceCount = 1;
  385. const RHI::ShaderResourceGroup* shaderResourceGroups[] = { m_customMSAAResolveShaderResourceGroup->GetRHIShaderResourceGroup() };
  386. RHI::DrawItem drawItem;
  387. drawItem.m_arguments = drawIndexed;
  388. drawItem.m_pipelineState = m_customResolveMSAAPipelineState.get();
  389. drawItem.m_indexBufferView = &indexBufferView;
  390. drawItem.m_shaderResourceGroupCount = static_cast<uint8_t>(RHI::ArraySize(shaderResourceGroups));
  391. drawItem.m_shaderResourceGroups = shaderResourceGroups;
  392. drawItem.m_streamBufferViewCount = static_cast<uint8_t>(m_quadStreamBufferViews.size());
  393. drawItem.m_streamBufferViews = m_quadStreamBufferViews.data();
  394. // Submit the triangle draw item.
  395. commandList->Submit(drawItem);
  396. };
  397. m_MSAAScopeProducers[static_cast<uint32_t>(MSAAType::MSAA4X_Custom_Resolve)].emplace_back(
  398. aznew RHI::ScopeProducerFunction<
  399. ScopeData,
  400. decltype(prepareFunction),
  401. decltype(compileFunction),
  402. decltype(executeFunction)>(
  403. AZ::RHI::ScopeId("Resolve"),
  404. ScopeData{ },
  405. prepareFunction,
  406. compileFunction,
  407. executeFunction));
  408. }
  409. } // namespace AtomSampleViewer