You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.4 KiB
C++
96 lines
3.4 KiB
C++
/*
|
|
* 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 <Atom/RPI.Public/Shader/ShaderResourceGroupPool.h>
|
|
|
|
#include <Atom/RHI/Factory.h>
|
|
#include <Atom/RHI/RHISystemInterface.h>
|
|
|
|
#include <AtomCore/Instance/InstanceDatabase.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace RPI
|
|
{
|
|
Data::Instance<ShaderResourceGroupPool> ShaderResourceGroupPool::FindOrCreate(const Data::Asset<ShaderResourceGroupAsset>& srgAsset)
|
|
{
|
|
return Data::InstanceDatabase<ShaderResourceGroupPool>::Instance().FindOrCreate(
|
|
Data::InstanceId::CreateFromAssetId(srgAsset.GetId()),
|
|
srgAsset);
|
|
}
|
|
|
|
Data::Instance<ShaderResourceGroupPool> ShaderResourceGroupPool::CreateInternal(ShaderResourceGroupAsset& srgAsset)
|
|
{
|
|
Data::Instance<ShaderResourceGroupPool> srgPool = aznew ShaderResourceGroupPool();
|
|
const RHI::ResultCode resultCode = srgPool->Init(srgAsset);
|
|
|
|
if (resultCode == RHI::ResultCode::Success)
|
|
{
|
|
return srgPool;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
RHI::ResultCode ShaderResourceGroupPool::Init(ShaderResourceGroupAsset& srgAsset)
|
|
{
|
|
RHI::Ptr<RHI::Device> device = RHI::RHISystemInterface::Get()->GetDevice();
|
|
|
|
m_pool = RHI::Factory::Get().CreateShaderResourceGroupPool();
|
|
if (!m_pool)
|
|
{
|
|
AZ_Error("ShaderResourceGroupPool", false, "Failed to create RHI::ShaderResourceGroupPool");
|
|
return RHI::ResultCode::Fail;
|
|
}
|
|
|
|
RHI::ShaderResourceGroupPoolDescriptor poolDescriptor;
|
|
poolDescriptor.m_layout = srgAsset.GetLayout();
|
|
|
|
|
|
m_pool->SetName(Name(srgAsset.GetName()));
|
|
const RHI::ResultCode resultCode = m_pool->Init(*device, poolDescriptor);
|
|
|
|
AZ_Error("ShaderResourceGroupPool", resultCode == RHI::ResultCode::Success, "Failed to initialize RHI::ShaderResourceGroupPool");
|
|
|
|
return resultCode;
|
|
}
|
|
|
|
RHI::Ptr<RHI::ShaderResourceGroup> ShaderResourceGroupPool::CreateRHIShaderResourceGroup()
|
|
{
|
|
RHI::Ptr<RHI::ShaderResourceGroup> srg = RHI::Factory::Get().CreateShaderResourceGroup();
|
|
AZ_Error("ShaderResourceGroupPool", srg, "Failed to create RHI::ShaderResourceGroup");
|
|
|
|
if (srg)
|
|
{
|
|
RHI::ResultCode result = m_pool->InitGroup(*srg);
|
|
if (result != RHI::ResultCode::Success)
|
|
{
|
|
srg.reset();
|
|
AZ_Error("ShaderResourceGroupPool", false, "Failed to initialize RHI::ShaderResourceGroup");
|
|
}
|
|
}
|
|
|
|
return srg;
|
|
}
|
|
|
|
RHI::ShaderResourceGroupPool* ShaderResourceGroupPool::GetRHIPool()
|
|
{
|
|
return m_pool.get();
|
|
}
|
|
|
|
const RHI::ShaderResourceGroupPool* ShaderResourceGroupPool::GetRHIPool() const
|
|
{
|
|
return m_pool.get();
|
|
}
|
|
}
|
|
}
|