Commit 214b0f7b authored by Erik Faye-Lund 's avatar Erik Faye-Lund

d3d12: get rid of pointless SubresourceInfo struct

parent 3f5c8801
......@@ -24,58 +24,58 @@
#include "D3D12ResourceState.h"
//----------------------------------------------------------------------------------------------------------------------------------
CDesiredResourceState::SubresourceInfo const& CDesiredResourceState::GetSubresourceInfo(UINT SubresourceIndex) const
D3D12_RESOURCE_STATES CDesiredResourceState::GetSubresourceState(UINT SubresourceIndex) const
{
if (AreAllSubresourcesSame())
{
SubresourceIndex = 0;
}
return m_spSubresourceInfo[SubresourceIndex];
return m_spSubresourceStates[SubresourceIndex];
}
//----------------------------------------------------------------------------------------------------------------------------------
void CDesiredResourceState::UpdateSubresourceState(unsigned SubresourceIndex, SubresourceInfo const& info)
void CDesiredResourceState::UpdateSubresourceState(unsigned SubresourceIndex, D3D12_RESOURCE_STATES state)
{
assert(SubresourceIndex < m_spSubresourceInfo.size());
if (m_spSubresourceInfo[SubresourceIndex].State == UNKNOWN_RESOURCE_STATE ||
info.State == UNKNOWN_RESOURCE_STATE ||
IsD3D12WriteState(info.State))
assert(SubresourceIndex < m_spSubresourceStates.size());
if (m_spSubresourceStates[SubresourceIndex] == UNKNOWN_RESOURCE_STATE ||
state == UNKNOWN_RESOURCE_STATE ||
IsD3D12WriteState(state))
{
m_spSubresourceInfo[SubresourceIndex] = info;
m_spSubresourceStates[SubresourceIndex] = state;
}
else
{
// Accumulate read state state bits
m_spSubresourceInfo[SubresourceIndex].State |= info.State;
m_spSubresourceStates[SubresourceIndex] |= state;
}
}
//----------------------------------------------------------------------------------------------------------------------------------
void CDesiredResourceState::SetResourceState(SubresourceInfo const & Info)
void CDesiredResourceState::SetResourceState(D3D12_RESOURCE_STATES state)
{
m_bAllSubresourcesSame = true;
UpdateSubresourceState(0, Info);
UpdateSubresourceState(0, state);
}
//----------------------------------------------------------------------------------------------------------------------------------
void CDesiredResourceState::SetSubresourceState(UINT SubresourceIndex, SubresourceInfo const & Info)
void CDesiredResourceState::SetSubresourceState(UINT SubresourceIndex, D3D12_RESOURCE_STATES state)
{
if (m_bAllSubresourcesSame && m_spSubresourceInfo.size() > 1)
if (m_bAllSubresourcesSame && m_spSubresourceStates.size() > 1)
{
std::fill(m_spSubresourceInfo.begin() + 1, m_spSubresourceInfo.end(), m_spSubresourceInfo[0]);
std::fill(m_spSubresourceStates.begin() + 1, m_spSubresourceStates.end(), m_spSubresourceStates[0]);
m_bAllSubresourcesSame = false;
}
if (m_spSubresourceInfo.size() == 1)
if (m_spSubresourceStates.size() == 1)
{
SubresourceIndex = 0;
}
UpdateSubresourceState(SubresourceIndex, Info);
UpdateSubresourceState(SubresourceIndex, state);
}
//----------------------------------------------------------------------------------------------------------------------------------
void CDesiredResourceState::Reset()
{
SetResourceState(SubresourceInfo{});
SetResourceState(UNKNOWN_RESOURCE_STATE);
}
//----------------------------------------------------------------------------------------------------------------------------------
......@@ -169,9 +169,9 @@ ResourceStateManager::ResourceStateManager()
//----------------------------------------------------------------------------------------------------------------------------------
void ResourceStateManager::TransitionResource(TransitionableResourceState& Resource,
CDesiredResourceState::SubresourceInfo const& State)
D3D12_RESOURCE_STATES state)
{
Resource.m_DesiredState.SetResourceState(State);
Resource.m_DesiredState.SetResourceState(state);
if (!Resource.IsTransitionPending())
{
list_add(&Resource.m_TransitionListEntry, &m_TransitionListHead);
......@@ -180,10 +180,10 @@ void ResourceStateManager::TransitionResource(TransitionableResourceState& Resou
//----------------------------------------------------------------------------------------------------------------------------------
void ResourceStateManager::TransitionSubresource(TransitionableResourceState& Resource,
UINT SubresourceIndex,
CDesiredResourceState::SubresourceInfo const& State)
UINT SubresourceIndex,
D3D12_RESOURCE_STATES state)
{
Resource.m_DesiredState.SetSubresourceState(SubresourceIndex, State);
Resource.m_DesiredState.SetSubresourceState(SubresourceIndex, state);
if (!Resource.IsTransitionPending())
{
list_add(&Resource.m_TransitionListEntry, &m_TransitionListHead);
......@@ -263,11 +263,11 @@ void ResourceStateManager::ProcessTransitioningResource(ID3D12Resource* pTransit
UINT numSubresources = bAllSubresourcesAtOnce ? 1 : NumTotalSubresources;
for (UINT i = 0; i < numSubresources; ++i)
{
CDesiredResourceState::SubresourceInfo SubresourceDestinationInfo = DestinationState.GetSubresourceInfo(i);
D3D12_RESOURCE_STATES SubresourceDestinationState = DestinationState.GetSubresourceState(i);
TransitionDesc.Transition.Subresource = bAllSubresourcesAtOnce ? D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES : i;
// Is this subresource currently being used, or is it just being iterated over?
D3D12_RESOURCE_STATES after = SubresourceDestinationInfo.State;
D3D12_RESOURCE_STATES after = DestinationState.GetSubresourceState(i);
if (after == UNKNOWN_RESOURCE_STATE)
{
// This subresource doesn't have any transition requested - move on to the next.
......@@ -277,19 +277,16 @@ void ResourceStateManager::ProcessTransitioningResource(ID3D12Resource* pTransit
ProcessTransitioningSubresourceExplicit(
CurrentState,
i,
SubresourceDestinationInfo,
SubresourceDestinationState,
after,
TransitionableResourceState,
TransitionDesc,
ExecutionId); // throw( bad_alloc )
}
CDesiredResourceState::SubresourceInfo UnknownDestinationState = {};
UnknownDestinationState.State = UNKNOWN_RESOURCE_STATE;
// Update destination states.
// Coalesce destination state to ensure that it's set for the entire resource.
DestinationState.SetResourceState(UnknownDestinationState);
DestinationState.SetResourceState(UNKNOWN_RESOURCE_STATE);
}
......@@ -297,7 +294,7 @@ void ResourceStateManager::ProcessTransitioningResource(ID3D12Resource* pTransit
void ResourceStateManager::ProcessTransitioningSubresourceExplicit(
CCurrentResourceState& CurrentState,
UINT SubresourceIndex,
CDesiredResourceState::SubresourceInfo& SubresourceDestinationInfo,
D3D12_RESOURCE_STATES state,
D3D12_RESOURCE_STATES after,
TransitionableResourceState& TransitionableResourceState,
D3D12_RESOURCE_BARRIER& TransitionDesc,
......@@ -369,15 +366,13 @@ void ResourceStateManager::SubmitResourceTransitions(ID3D12GraphicsCommandList *
//----------------------------------------------------------------------------------------------------------------------------------
void ResourceStateManager::TransitionResource(TransitionableResourceState* pResource, D3D12_RESOURCE_STATES State)
{
CDesiredResourceState::SubresourceInfo DesiredState = { State };
ResourceStateManager::TransitionResource(*pResource, DesiredState);
ResourceStateManager::TransitionResource(*pResource, State);
}
//----------------------------------------------------------------------------------------------------------------------------------
void ResourceStateManager::TransitionSubresource(TransitionableResourceState* pResource, UINT SubresourceIndex, D3D12_RESOURCE_STATES State)
{
CDesiredResourceState::SubresourceInfo DesiredState = { State };
ResourceStateManager::TransitionSubresource(*pResource, SubresourceIndex, DesiredState);
ResourceStateManager::TransitionSubresource(*pResource, SubresourceIndex, State);
}
//----------------------------------------------------------------------------------------------------------------------------------
......
......@@ -61,33 +61,27 @@ inline bool SupportsSimultaneousAccess(const D3D12_RESOURCE_DESC &desc)
//==================================================================================================================================
class CDesiredResourceState
{
public:
struct SubresourceInfo
{
D3D12_RESOURCE_STATES State = UNKNOWN_RESOURCE_STATE;
};
private:
bool m_bAllSubresourcesSame = true;
std::vector<SubresourceInfo> m_spSubresourceInfo;
std::vector<D3D12_RESOURCE_STATES> m_spSubresourceStates;
public:
CDesiredResourceState(UINT SubresourceCount) :
m_spSubresourceInfo(SubresourceCount)
m_spSubresourceStates(SubresourceCount)
{
}
bool AreAllSubresourcesSame() const { return m_bAllSubresourcesSame; }
SubresourceInfo const& GetSubresourceInfo(UINT SubresourceIndex) const;
void SetResourceState(SubresourceInfo const& Info);
void SetSubresourceState(UINT SubresourceIndex, SubresourceInfo const& Info);
D3D12_RESOURCE_STATES GetSubresourceState(UINT SubresourceIndex) const;
void SetResourceState(D3D12_RESOURCE_STATES state);
void SetSubresourceState(UINT SubresourceIndex, D3D12_RESOURCE_STATES state);
void Reset();
private:
void UpdateSubresourceState(unsigned SubresourceIndex, SubresourceInfo const& info);
void UpdateSubresourceState(unsigned SubresourceIndex, D3D12_RESOURCE_STATES state);
};
//==================================================================================================================================
......@@ -121,7 +115,7 @@ public:
// Returns the destination state if the current state is promotable.
// Returns D3D12_RESOURCE_STATE_COMMON if not.
D3D12_RESOURCE_STATES StateIfPromoted(D3D12_RESOURCE_STATES State, UINT SubresourceIndex);
D3D12_RESOURCE_STATES StateIfPromoted(D3D12_RESOURCE_STATES state, UINT SubresourceIndex);
bool AreAllSubresourcesSame() const { return m_bAllSubresourcesSame; }
......@@ -238,10 +232,10 @@ public:
private:
// These methods set the destination state of the resource/subresources and ensure it's in the transition list.
void TransitionResource(TransitionableResourceState& Resource,
CDesiredResourceState::SubresourceInfo const& State);
D3D12_RESOURCE_STATES State);
void TransitionSubresource(TransitionableResourceState& Resource,
UINT SubresourceIndex,
CDesiredResourceState::SubresourceInfo const& State);
D3D12_RESOURCE_STATES State);
// Clear out any state from previous iterations.
void ApplyResourceTransitionsPreamble();
......@@ -285,7 +279,7 @@ private:
const CCurrentResourceState::LogicalState &NewLogicalState);
void ProcessTransitioningSubresourceExplicit(CCurrentResourceState& CurrentState,
UINT i,
CDesiredResourceState::SubresourceInfo& SubresourceDestinationInfo,
D3D12_RESOURCE_STATES state,
D3D12_RESOURCE_STATES after,
TransitionableResourceState& TransitionableResourceState,
D3D12_RESOURCE_BARRIER& TransitionDesc,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment