MaterialHotReloadTest.bv.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ----------------------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. g_screenshotOutputFolder = ResolvePath('@user@/Scripts/Screenshots/MaterialHotReloadTest/')
  12. Print('Saving screenshots to ' .. NormalizePath(g_screenshotOutputFolder))
  13. g_assetFolder = "materials/hotreloadtest/temp/";
  14. OpenSample('RPI/MaterialHotReloadTest')
  15. ResizeViewport(500, 500)
  16. SelectImageComparisonToleranceLevel("Level E")
  17. function SetColorRed()
  18. AssetTracking_Start()
  19. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.material")
  20. SetImguiValue('ColorA = Red', true)
  21. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  22. IdleSeconds(0.25) -- Idle for a bit to give time for the asset to reload
  23. end
  24. function SetBlendingOn()
  25. AssetTracking_Start()
  26. SetImguiValue('Blending On', true)
  27. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.materialtype")
  28. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shader")
  29. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  30. IdleSeconds(1) -- Idle for a bit to give time for the assets to reload
  31. end
  32. function SetBlendingOff()
  33. AssetTracking_Start()
  34. SetImguiValue('Blending Off', true)
  35. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.materialtype")
  36. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shader")
  37. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  38. IdleSeconds(1) -- Idle for a bit to give time for the assets to reload
  39. end
  40. CaptureScreenshot(g_screenshotOutputFolder .. '/01_Default.png')
  41. SetColorRed()
  42. CaptureScreenshot(g_screenshotOutputFolder .. '/02_Red.png')
  43. AssetTracking_Start()
  44. SetImguiValue('ColorA = Blue', true)
  45. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.material")
  46. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  47. IdleSeconds(0.25) -- Idle for a bit to give time for the asset to reload
  48. CaptureScreenshot(g_screenshotOutputFolder .. '/03_Blue.png')
  49. AssetTracking_Start()
  50. SetImguiValue('Default Colors', true)
  51. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.material")
  52. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  53. IdleSeconds(0.25) -- Idle for a bit to give time for the asset to reload
  54. CaptureScreenshot(g_screenshotOutputFolder .. '/04_DefaultAgain.png')
  55. AssetTracking_Start()
  56. SetImguiValue('Wavy Lines', true)
  57. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.materialtype")
  58. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  59. IdleSeconds(0.25) -- Idle for a bit to give time for the assets to reload
  60. CaptureScreenshot(g_screenshotOutputFolder .. '/05_WavyLines.png')
  61. AssetTracking_Start()
  62. SetImguiValue('Vertical Pattern', true)
  63. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.materialtype")
  64. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shader")
  65. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  66. IdleSeconds(1) -- Idle for a bit to give time for the assets to reload
  67. CaptureScreenshot(g_screenshotOutputFolder .. '/06_VerticalPattern.png')
  68. SetBlendingOn()
  69. CaptureScreenshot(g_screenshotOutputFolder .. '/07_BlendingOn.png')
  70. -- This will switch to showing the "Shader Variant: Fully Baked" message
  71. AssetTracking_Start()
  72. SetImguiValue('ShaderVariantList/All', true)
  73. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shadervariantlist", 3) -- Waiting for 3 products, the list asset and two variant assets
  74. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  75. IdleSeconds(1) -- Idle for a bit to give time for the assets to reload
  76. CaptureScreenshot(g_screenshotOutputFolder .. '/08_Variants_All.png')
  77. -- This will switch to showing the "Shader Variant: Root" message
  78. AssetTracking_Start()
  79. SetImguiValue('ShaderVariantList/Only Straight Lines', true)
  80. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shadervariantlist", 2) -- Waiting for 2 products, the list asset and one variant assets
  81. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  82. IdleSeconds(0.25) -- Idle for a bit to give time for the assets to reload
  83. CaptureScreenshot(g_screenshotOutputFolder .. '/09_Variants_OnlyStraightLines.png')
  84. -- This will switch to showing the "Shader Variant: Fully Baked" message again
  85. AssetTracking_Start()
  86. SetImguiValue('ShaderVariantList/Only Wavy Lines', true)
  87. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shadervariantlist", 2) -- Waiting for 2 products, the list asset and one variant assets
  88. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  89. IdleSeconds(0.25) -- Idle for a bit to give time for the assets to reload
  90. CaptureScreenshot(g_screenshotOutputFolder .. '/10_Variants_OnlyWavyLines.png')
  91. -- This screenshot will be identical to the one above because the variants
  92. -- are still loaded in memory even though they have been removed from disk
  93. AssetTracking_Start()
  94. SetImguiValue('ShaderVariantList/None', true)
  95. IdleSeconds(1.0) -- Idle for a bit to give time for the assets to disappear
  96. CaptureScreenshot(g_screenshotOutputFolder .. '/11_Variants_None.png')
  97. -- Now, changing the .shader file will force the shader to reload and will not find
  98. -- any baked variants, since we switched to "None" above, and so this screenshot will
  99. -- switch back to showing the "Shader Variant: Root" message.
  100. SetBlendingOff()
  101. --[GFX TODO] This test is consistently failing due to an Asset Processor bug. Re-enable this test once that is fixed.
  102. --CaptureScreenshot(g_screenshotOutputFolder .. '/12_Variants_None_AfterUpdatingShader.png')
  103. -- Here we prepare to test a specific edge case. First, the material should be using a full baked shader variant, so we set up that precondition and verify with a screenshot.
  104. AssetTracking_Start()
  105. SetImguiValue('ShaderVariantList/All', true)
  106. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shadervariantlist", 3) -- Waiting for 3 products, the list asset and two variant assets
  107. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  108. IdleSeconds(1) -- Idle for a bit to give time for the assets to reload
  109. CaptureScreenshot(g_screenshotOutputFolder .. '/13_Variants_All.png')
  110. -- Now that the material is using a fully-baked variant, modify the .azsl file to force *everything* to rebuild. In the failure case, the runtime
  111. -- holds onto the old fully-baked variant even though a new root variant is available. In the correct case, the root variant should take priority
  112. -- over the fully-baked variant because it is more recent.
  113. AssetTracking_Start()
  114. SetImguiValue('Horizontal Pattern', true)
  115. -- Note that here we explicitly do NOT wait for HotReloadTest.shadervariantlist even though the ShaderVariantAssets will be rebuild here too;
  116. -- part of this test is to ensure the updated shader code is used as soon as the root variant is available.
  117. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.materialtype")
  118. AssetTracking_ExpectAsset(g_assetFolder .. "HotReloadTest.shader")
  119. AssetTracking_IdleUntilExpectedAssetsFinish(10)
  120. -- We want this idle to be short enough that the ShaderVariantAssets don't have time to finish building before we take the screenshot, as part
  121. -- of the validation that the root variant gets applied asap. But it also needs to be long enough to account for some delay between the
  122. -- AssetTracking utility and the asset system triggering the reload. We should avoid increasing this if possible (but maybe we'll have no
  123. -- choice ... we'll see)
  124. IdleSeconds(0.25) -- Idle for a bit to give time for the assets to reload
  125. CaptureScreenshot(g_screenshotOutputFolder .. '/14_HorizontalPattern.png')
  126. -- Test a specific scenario that was failing, where color changes fail to reload after making a shader change.
  127. SetBlendingOn()
  128. SetBlendingOff()
  129. SetColorRed()
  130. CaptureScreenshot(g_screenshotOutputFolder .. '/15_Red_AfterShaderReload.png')