3
0

ShaderVariantListSourceData.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/RPI.Edit/Common/JsonUtils.h>
  9. #include <Atom/RPI.Edit/Shader/ShaderVariantListSourceData.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. namespace AZ
  14. {
  15. namespace RPI
  16. {
  17. void ShaderVariantListSourceData::Reflect(ReflectContext* context)
  18. {
  19. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  20. {
  21. serializeContext->Class<VariantInfo>()
  22. ->Version(2) // Added Radeon GPU Analyzer
  23. ->Field("StableId", &VariantInfo::m_stableId)
  24. ->Field("Options", &VariantInfo::m_options)
  25. ->Field("EnableAnalysis", &VariantInfo::m_enableRegisterAnalysis)
  26. ->Field("Asic", &VariantInfo::m_asic)
  27. ;
  28. serializeContext->Class<ShaderVariantListSourceData>()
  29. ->Version(1)
  30. ->Field("Shader", &ShaderVariantListSourceData::m_shaderFilePath)
  31. ->Field("Variants", &ShaderVariantListSourceData::m_shaderVariants)
  32. ;
  33. if (auto editContext = serializeContext->GetEditContext())
  34. {
  35. editContext->Class<VariantInfo>("VariantInfo", "")
  36. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  37. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  38. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_stableId, "Stable Id", "Unique identifier for this shader variant within the list")
  39. ->Attribute(AZ::Edit::Attributes::ReadOnly, true)
  40. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_options, "Options", "Table of shader options for configuring this variant")
  41. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  42. ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false)
  43. ->Attribute(AZ::Edit::Attributes::ContainerReorderAllow, false)
  44. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_enableRegisterAnalysis, "Register Analysis", "Whether to output analysis data from Radeon GPU Analyzer")
  45. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_asic, "GPU target", "The GPU target to use on register analysis")
  46. ;
  47. editContext->Class<ShaderVariantListSourceData>("ShaderVariantListSourceData", "")
  48. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  49. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  50. ->DataElement(AZ::Edit::UIHandlers::Default, &ShaderVariantListSourceData::m_shaderFilePath, "Shader File Path", "Path to the shader source this variant list represents")
  51. ->Attribute(AZ::Edit::Attributes::ReadOnly, true)
  52. ->DataElement(AZ::Edit::UIHandlers::Default, &ShaderVariantListSourceData::m_shaderVariants, "Shader Variants", "Container of all variants and options configured for the shader")
  53. ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false)
  54. ->Attribute(AZ::Edit::Attributes::ContainerReorderAllow, false)
  55. ;
  56. }
  57. }
  58. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  59. {
  60. behaviorContext->Class<VariantInfo>("ShaderVariantInfo")
  61. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  62. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  63. ->Attribute(AZ::Script::Attributes::Module, "shader")
  64. ->Property("stableId", BehaviorValueGetter(&VariantInfo::m_stableId), BehaviorValueSetter(&VariantInfo::m_stableId))
  65. ->Property("options", BehaviorValueGetter(&VariantInfo::m_options), BehaviorValueSetter(&VariantInfo::m_options))
  66. ->Property("enableAnalysis", BehaviorValueGetter(&VariantInfo::m_enableRegisterAnalysis), BehaviorValueSetter(&VariantInfo::m_enableRegisterAnalysis))
  67. ->Property("asic", BehaviorValueGetter(&VariantInfo::m_asic), BehaviorValueSetter(&VariantInfo::m_asic))
  68. ;
  69. behaviorContext->Class<ShaderVariantListSourceData>("ShaderVariantListSourceData")
  70. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  71. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  72. ->Attribute(AZ::Script::Attributes::Module, "shader")
  73. ->Property("shaderFilePath", BehaviorValueGetter(&ShaderVariantListSourceData::m_shaderFilePath), BehaviorValueSetter(&ShaderVariantListSourceData::m_shaderFilePath))
  74. ->Property("shaderVariants", BehaviorValueGetter(&ShaderVariantListSourceData::m_shaderVariants), BehaviorValueSetter(&ShaderVariantListSourceData::m_shaderVariants))
  75. ;
  76. // [GFX TODO][ATOM-14858] Expose JsonUtils to Behavior Context in JsonUtils.cpp and make it generic
  77. behaviorContext->Method("SaveShaderVariantListSourceData", &JsonUtils::SaveObjectToFile<ShaderVariantListSourceData>)
  78. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  79. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  80. ->Attribute(AZ::Script::Attributes::Module, "shader")
  81. ;
  82. }
  83. }
  84. } // namespace RPI
  85. } // namespace AZ