Fixed race conditions that could prevent successful hot-reload of shaders.
ATOM-15728 Shader Hot Reload Fails in Debug Build The main change was to add OnAssetReady handlers to each of the asset classes. See comments in ShaderAsset::OnAssetReady for a detailed explanation. In short, OnAssetReloaded gets missed while assets are being reloaded at the same time on multiple threads, but OnAssetReady is always called whenever connecting to the AssetBus because of its AssetConnectionPolicy. The above change required the addition of a new AssetInitBus to call the PostLoadInit() functions. Because OnAssetReady connects to buses that are not mutex-protected, they have to be connected on the main thread. AssetInitBus::PostLoadInit is called every frame in RPISystem::SimulationTick. All Atom's asset handlers that need to do post-load initialization must connect to the AssetInitBus, and the asset will disconnect itself after initialization is complete. We also need the Shader class to handle OnShaderAssetReinitialized to properly handle the shader reload. With these changes I can click back and forth between "Blending On" and "Blending Off" many times (like 20 times) without issue.main
parent
406792606b
commit
982406d4d5
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
//! Bus for post-load initialization of assets.
|
||||
//! Assets that need to do post-load initialization should connect to this bus in their asset handler's LoadAssetData() function.
|
||||
//! Be sure to disconnect from this bus as soon as initialization is complete, as it will be called every frame.
|
||||
class AssetInitEvents
|
||||
: public EBusTraits
|
||||
{
|
||||
public:
|
||||
// EBus Configuration
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
typedef AZStd::recursive_mutex MutexType;
|
||||
|
||||
//! This function is called every frame on the main thread to perform any necessary post-load initialization.
|
||||
//! Connect to the bus after loading the asset data, and disconnect when initialization is complete.
|
||||
//! @return whether initialization was successful
|
||||
virtual bool PostLoadInit() = 0;
|
||||
};
|
||||
|
||||
using AssetInitBus = AZ::EBus<AssetInitEvents>;
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
Loading…
Reference in New Issue