/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace RPI { static constexpr char ShaderSystemLog[] = "ShaderSystem"; void ShaderSystem::Reflect(ReflectContext* context) { ShaderResourceGroupAsset::Reflect(context); ShaderOptionDescriptor::Reflect(context); ShaderOptionGroupLayout::Reflect(context); ShaderOptionGroupHints::Reflect(context); ShaderOptionGroup::Reflect(context); ShaderVariantId::Reflect(context); ShaderVariantStableId::Reflect(context); ShaderAsset::Reflect(context); ShaderAsset2::Reflect(context); ShaderInputContract::Reflect(context); ShaderOutputContract::Reflect(context); ShaderVariantAsset::Reflect(context); ShaderVariantAsset2::Reflect(context); ShaderVariantTreeAsset::Reflect(context); ReflectShaderStageType(context); PrecompiledShaderAssetSourceData::Reflect(context); } ShaderSystemInterface* ShaderSystemInterface::Get() { return Interface::Get(); } void ShaderSystem::GetAssetHandlers(AssetHandlerPtrList& assetHandlers) { assetHandlers.emplace_back(MakeAssetHandler()); assetHandlers.emplace_back(MakeAssetHandler()); assetHandlers.emplace_back(MakeAssetHandler()); assetHandlers.emplace_back(MakeAssetHandler()); assetHandlers.emplace_back(MakeAssetHandler()); assetHandlers.emplace_back(MakeAssetHandler()); } void ShaderSystem::Init() { m_shaderVariantAsyncLoader.Init(); Interface::Register(this); { Data::InstanceHandler handler; handler.m_createFunction = [](Data::AssetData* shaderAsset) { return Shader::CreateInternal(*(azrtti_cast(shaderAsset))); }; Data::InstanceDatabase::Create(azrtti_typeid(), handler); } { Data::InstanceHandler handler; handler.m_createFunction = [](Data::AssetData* shaderAsset) { return Shader2::CreateInternal(*(azrtti_cast(shaderAsset))); }; Data::InstanceDatabase::Create(azrtti_typeid(), handler); } { Data::InstanceHandler handler; handler.m_createFunction = [](Data::AssetData* srgAsset) { return ShaderResourceGroup::CreateInternal(*(azrtti_cast(srgAsset))); }; Data::InstanceDatabase::Create(azrtti_typeid(), handler); } { Data::InstanceHandler handler; handler.m_createFunction = [](Data::AssetData* srgAsset) { return ShaderResourceGroupPool::CreateInternal(*(azrtti_cast(srgAsset))); }; Data::InstanceDatabase::Create(azrtti_typeid(), handler); } } void ShaderSystem::Shutdown() { Data::InstanceDatabase::Destroy(); Data::InstanceDatabase::Destroy(); Data::InstanceDatabase::Destroy(); Data::InstanceDatabase::Destroy(); Interface::Unregister(this); m_shaderVariantAsyncLoader.Shutdown(); } /////////////////////////////////////////////////////////////////// // ShaderSystemInterface overrides void ShaderSystem::SetGlobalShaderOption(const AZ::Name& shaderOptionName, ShaderOptionValue value) { bool changed = false; auto iter = m_globalShaderOptionValues.find(shaderOptionName); if (iter == m_globalShaderOptionValues.end()) { changed = true; m_globalShaderOptionValues[shaderOptionName] = value; } else if (iter->second != value) { iter->second = value; changed = true; } if (changed) { m_globalShaderOptionUpdatedEvent.Signal(shaderOptionName, AZStd::move(value)); } } ShaderOptionValue ShaderSystem::GetGlobalShaderOption(const AZ::Name& shaderOptionName) { ShaderOptionValue value; auto iter = m_globalShaderOptionValues.find(shaderOptionName); if (iter != m_globalShaderOptionValues.end()) { value = iter->second; } return value; } const ShaderSystem::GlobalShaderOptionMap& ShaderSystem::GetGlobalShaderOptions() const { return m_globalShaderOptionValues; } void ShaderSystem::Connect(GlobalShaderOptionUpdatedEvent::Handler& handler) { handler.Connect(m_globalShaderOptionUpdatedEvent); } /////////////////////////////////////////////////////////////////// } // namespace RPI } // namespace AZ