Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Erik Faye-Lund
mesa
Commits
212b25b1
Commit
212b25b1
authored
May 27, 2020
by
Erik Faye-Lund
Browse files
d3d12: use util/list.h instead of open-coded list
This gets rid of some repeated code.
parent
70c313d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/microsoft/resource_state_manager/D3D12ResourceState.cpp
View file @
212b25b1
...
...
@@ -164,7 +164,7 @@ void CCurrentResourceState::Reset()
//----------------------------------------------------------------------------------------------------------------------------------
ResourceStateManager
::
ResourceStateManager
()
{
InitializeListH
ead
(
&
m_TransitionListHead
);
list_inith
ead
(
&
m_TransitionListHead
);
// Reserve some space in these vectors upfront. Values are arbitrary.
m_vResourceBarriers
.
reserve
(
50
);
}
...
...
@@ -176,7 +176,7 @@ void ResourceStateManager::TransitionResource(TransitionableResourceState& Resou
Resource
.
m_DesiredState
.
SetResourceState
(
State
);
if
(
!
Resource
.
IsTransitionPending
())
{
InsertHeadList
(
&
m_TransitionListHead
,
&
Resource
.
m_TransitionList
Entry
);
list_add
(
&
Resource
.
m_TransitionListEntry
,
&
m_TransitionList
Head
);
}
}
...
...
@@ -188,7 +188,7 @@ void ResourceStateManager::TransitionSubresource(TransitionableResourceState& Re
Resource
.
m_DesiredState
.
SetSubresourceState
(
SubresourceIndex
,
State
);
if
(
!
Resource
.
IsTransitionPending
())
{
InsertHeadList
(
&
m_TransitionListHead
,
&
Resource
.
m_TransitionList
Entry
);
list_add
(
&
Resource
.
m_TransitionListEntry
,
&
m_TransitionList
Head
);
}
}
...
...
src/microsoft/resource_state_manager/D3D12ResourceState.h
View file @
212b25b1
...
...
@@ -28,6 +28,8 @@
#include <assert.h>
#include <d3d12.h>
#include "util/list.h"
#include "D3D12StateTransitionFlags.h"
#define UNKNOWN_RESOURCE_STATE (D3D12_RESOURCE_STATES)0x8000u
...
...
@@ -50,77 +52,6 @@ inline bool IsD3D12WriteState(UINT State, SubresourceTransitionFlags Flags)
(
Flags
&
SubresourceTransitionFlags_ForceExplicitState
)
!=
SubresourceTransitionFlags_None
;
}
// BUGBUG: Consider replacing with existing list implementations in Mesa source
typedef
struct
_STATE_LIST_ENTRY
{
struct
_STATE_LIST_ENTRY
*
Flink
;
struct
_STATE_LIST_ENTRY
*
Blink
;
}
STATE_LIST_ENTRY
,
*
PSTATE_LIST_ENTRY
,
*
RESTRICTED_POINTER
PRSTATE_LIST_ENTRY
;
#define STATE_CONTAINING_RECORD(address, type, field) ((type *)( \
(PCHAR)(address) - \
(ULONG_PTR)(&((type *)0)->field)))
inline
BOOLEAN
IsListEmpty
(
_In_
const
STATE_LIST_ENTRY
*
ListHead
)
{
return
(
BOOLEAN
)(
ListHead
->
Flink
==
ListHead
);
}
inline
void
InitializeListHead
(
_Out_
PSTATE_LIST_ENTRY
ListHead
)
{
ListHead
->
Flink
=
ListHead
->
Blink
=
ListHead
;
}
inline
BOOLEAN
RemoveEntryList
(
_In_
PSTATE_LIST_ENTRY
Entry
)
{
PSTATE_LIST_ENTRY
PrevEntry
;
PSTATE_LIST_ENTRY
NextEntry
;
NextEntry
=
Entry
->
Flink
;
PrevEntry
=
Entry
->
Blink
;
if
((
NextEntry
->
Blink
!=
Entry
)
||
(
PrevEntry
->
Flink
!=
Entry
))
{
assert
(
false
);
}
PrevEntry
->
Flink
=
NextEntry
;
NextEntry
->
Blink
=
PrevEntry
;
return
(
BOOLEAN
)(
PrevEntry
==
NextEntry
);
}
inline
void
InsertHeadList
(
_Inout_
PSTATE_LIST_ENTRY
ListHead
,
_Out_
PSTATE_LIST_ENTRY
Entry
)
{
PSTATE_LIST_ENTRY
NextEntry
;
NextEntry
=
ListHead
->
Flink
;
Entry
->
Flink
=
NextEntry
;
Entry
->
Blink
=
ListHead
;
if
(
NextEntry
->
Blink
!=
ListHead
)
{
assert
(
false
);
}
NextEntry
->
Blink
=
Entry
;
ListHead
->
Flink
=
Entry
;
return
;
}
inline
void
InsertTailList
(
_Inout_
PSTATE_LIST_ENTRY
ListHead
,
_Out_
__drv_aliasesMem
PSTATE_LIST_ENTRY
Entry
)
{
PSTATE_LIST_ENTRY
PrevEntry
;
PrevEntry
=
ListHead
->
Blink
;
Entry
->
Flink
=
ListHead
;
Entry
->
Blink
=
PrevEntry
;
if
(
PrevEntry
->
Flink
!=
ListHead
)
{
assert
(
false
);
}
PrevEntry
->
Flink
=
Entry
;
ListHead
->
Blink
=
Entry
;
return
;
}
inline
bool
SupportsSimultaneousAccess
(
const
D3D12_RESOURCE_DESC
&
desc
)
{
return
D3D12_RESOURCE_DIMENSION_BUFFER
==
desc
.
Dimension
||
...
...
@@ -211,7 +142,7 @@ public:
//==================================================================================================================================
struct
TransitionableResourceState
{
STATE_LIST_ENTRY
m_TransitionListEntry
;
struct
list_head
m_TransitionListEntry
;
CDesiredResourceState
m_DesiredState
;
TransitionableResourceState
(
ID3D12Resource
*
pResource
,
UINT
TotalSubresources
,
bool
SupportsSimultaneousAccess
)
:
...
...
@@ -220,18 +151,18 @@ struct TransitionableResourceState
m_currentState
(
TotalSubresources
,
SupportsSimultaneousAccess
),
m_pResource
(
pResource
)
{
InitializeListH
ead
(
&
m_TransitionListEntry
);
list_inith
ead
(
&
m_TransitionListEntry
);
}
~
TransitionableResourceState
()
{
if
(
IsTransitionPending
())
{
RemoveEntryList
(
&
m_TransitionListEntry
);
list_del
(
&
m_TransitionListEntry
);
}
}
bool
IsTransitionPending
()
const
{
return
!
IsListE
mpty
(
&
m_TransitionListEntry
);
}
bool
IsTransitionPending
()
const
{
return
!
list_is_e
mpty
(
&
m_TransitionListEntry
);
}
UINT
NumSubresources
()
{
return
m_TotalSubresources
;
}
...
...
@@ -280,7 +211,7 @@ class ResourceStateManager
{
protected:
STATE_LIST_ENTRY
m_TransitionListHead
;
struct
list_head
m_TransitionListHead
;
std
::
vector
<
D3D12_RESOURCE_BARRIER
>
m_vResourceBarriers
;
...
...
@@ -290,7 +221,7 @@ public:
~
ResourceStateManager
()
{
// All resources should be gone by this point, and each resource ensures it is no longer in this list.
assert
(
IsListE
mpty
(
&
m_TransitionListHead
));
assert
(
list_is_e
mpty
(
&
m_TransitionListHead
));
}
// Call the D3D12 APIs to perform the resource barriers, command list submission, and command queue sync
...
...
@@ -336,18 +267,14 @@ private:
template
<
typename
TFunc
>
void
ForEachTransitioningResource
(
TFunc
&&
func
)
{
for
(
STATE_LIST_ENTRY
*
pListEntry
=
m_TransitionListHead
.
Flink
;
pListEntry
!=
&
m_TransitionList
Head
;
)
list_for_each_entry_safe
(
TransitionableResourceState
,
pResource
,
&
m_TransitionListHead
,
m_TransitionList
Entry
)
{
TransitionableResourceState
*
pResource
=
STATE_CONTAINING_RECORD
(
pListEntry
,
TransitionableResourceState
,
m_TransitionListEntry
);
TransitionResult
result
=
func
(
*
pResource
);
auto
pNextListEntry
=
pListEntry
->
Flink
;
if
(
result
==
TransitionResult
::
Remove
)
{
RemoveEntryList
(
pListEntry
);
InitializeListHead
(
pListEntry
);
list_delinit
(
&
pResource
->
m_TransitionListEntry
);
}
pListEntry
=
pNextListEntry
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment