3
0

ShaderVariantListSourceData.cpp 6.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(2) // 2: addition of materialOptionsHint field
  30. ->Field("Shader", &ShaderVariantListSourceData::m_shaderFilePath)
  31. ->Field("Variants", &ShaderVariantListSourceData::m_shaderVariants)
  32. ->Field("MaterialOptionsHint", &ShaderVariantListSourceData::m_materialOptionsHint)
  33. ;
  34. if (auto editContext = serializeContext->GetEditContext())
  35. {
  36. editContext->Class<VariantInfo>("VariantInfo", "")
  37. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_stableId, "Stable Id", "Unique identifier for this shader variant within the list")
  40. ->Attribute(AZ::Edit::Attributes::ReadOnly, true)
  41. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_options, "Options", "Table of shader options for configuring this variant")
  42. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  43. ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false)
  44. ->Attribute(AZ::Edit::Attributes::ContainerReorderAllow, false)
  45. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_enableRegisterAnalysis, "Register Analysis", "Whether to output analysis data from Radeon GPU Analyzer")
  46. ->DataElement(AZ::Edit::UIHandlers::Default, &VariantInfo::m_asic, "GPU target", "The GPU target to use on register analysis")
  47. ;
  48. editContext->Class<ShaderVariantListSourceData>("ShaderVariantListSourceData", "")
  49. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  50. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  51. ->DataElement(AZ::Edit::UIHandlers::Default, &ShaderVariantListSourceData::m_shaderFilePath, "Shader File Path", "Path to the shader source this variant list represents")
  52. ->Attribute(AZ::Edit::Attributes::ReadOnly, true)
  53. ->DataElement(AZ::Edit::UIHandlers::Default, &ShaderVariantListSourceData::m_shaderVariants, "Shader Variants", "Container of all variants and options configured for the shader")
  54. ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false)
  55. ->Attribute(AZ::Edit::Attributes::ContainerReorderAllow, false)
  56. ;
  57. }
  58. }
  59. if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
  60. {
  61. behaviorContext->Class<VariantInfo>("ShaderVariantInfo")
  62. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  63. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  64. ->Attribute(AZ::Script::Attributes::Module, "shader")
  65. ->Property("stableId", BehaviorValueGetter(&VariantInfo::m_stableId), BehaviorValueSetter(&VariantInfo::m_stableId))
  66. ->Property("options", BehaviorValueGetter(&VariantInfo::m_options), BehaviorValueSetter(&VariantInfo::m_options))
  67. ->Property("enableAnalysis", BehaviorValueGetter(&VariantInfo::m_enableRegisterAnalysis), BehaviorValueSetter(&VariantInfo::m_enableRegisterAnalysis))
  68. ->Property("asic", BehaviorValueGetter(&VariantInfo::m_asic), BehaviorValueSetter(&VariantInfo::m_asic))
  69. ;
  70. behaviorContext->Class<ShaderVariantListSourceData>("ShaderVariantListSourceData")
  71. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  72. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  73. ->Attribute(AZ::Script::Attributes::Module, "shader")
  74. ->Property("shaderFilePath", BehaviorValueGetter(&ShaderVariantListSourceData::m_shaderFilePath), BehaviorValueSetter(&ShaderVariantListSourceData::m_shaderFilePath))
  75. ->Property("shaderVariants", BehaviorValueGetter(&ShaderVariantListSourceData::m_shaderVariants), BehaviorValueSetter(&ShaderVariantListSourceData::m_shaderVariants))
  76. ->Property("materialOptionsHint", BehaviorValueGetter(&ShaderVariantListSourceData::m_materialOptionsHint), BehaviorValueSetter(&ShaderVariantListSourceData::m_materialOptionsHint))
  77. ;
  78. // [GFX TODO][ATOM-14858] Expose JsonUtils to Behavior Context in JsonUtils.cpp and make it generic
  79. behaviorContext->Method("SaveShaderVariantListSourceData", &JsonUtils::SaveObjectToFile<ShaderVariantListSourceData>)
  80. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  81. ->Attribute(AZ::Script::Attributes::Category, "Shader")
  82. ->Attribute(AZ::Script::Attributes::Module, "shader")
  83. ;
  84. }
  85. }
  86. } // namespace RPI
  87. } // namespace AZ