Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/BlockAllocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ template<class _BlockType, class _SizeType = SIZE_T>
class CNullBlockAllocator
{
public:
_BlockType Allocate(_SizeType size) { return _BlockType; /* Returns a default block*/ }
_BlockType Allocate(_SizeType size) { return {}; /* Returns a default block*/ }
void Deallocate(_BlockType &block) { assert(block.GetSize() == 0); }
bool IsOwner(_BlockType &block) const { return block.GetSize() == 0 && block.GetOffset() == 0; }
void Reset() {}
Expand Down Expand Up @@ -105,7 +105,7 @@ class CPooledBlockAllocator
// Required Allocator functions
_BlockType Allocate(_SizeType size);
void Deallocate(const _BlockType &block);
bool IsOwner(const _BlockType &block) const { return block.GetSize() == blockSize; }
bool IsOwner(const _BlockType &block) const { return block.GetSize() == m_blockSize; }
void Reset();
};

Expand Down
5 changes: 3 additions & 2 deletions include/DeviceChild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace D3D12TranslationLayer
template <typename TIface>
void AddToDeferredDeletionQueue(unique_comptr<TIface>& spObject, COMMAND_LIST_TYPE CommandListType)
{
AddToDeferredDeletionQueue(spObject, CommandListType, m_pParent->GetCommandListID(CommandListType));
AddToDeferredDeletionQueue(spObject, CommandListType, GetCommandListID(CommandListType));
}

void SwapIdentities(DeviceChild& Other)
Expand All @@ -78,6 +78,7 @@ namespace D3D12TranslationLayer
}

void AddToDeferredDeletionQueue(ID3D12Object* pObject);
UINT64 GetCommandListID(COMMAND_LIST_TYPE CommandListType) noexcept;
};

template <typename TIface>
Expand All @@ -100,7 +101,7 @@ namespace D3D12TranslationLayer
}
TIface* GetForUse(COMMAND_LIST_TYPE CommandListType)
{
return GetForUse(CommandListType, m_pParent->GetCommandListID(CommandListType));
return GetForUse(CommandListType, GetCommandListID(CommandListType));
}
TIface* GetForImmediateUse() { return m_spIface.get(); }

Expand Down
20 changes: 10 additions & 10 deletions include/ImmediateContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CFencePool
TResourceType RetrieveFromPool(UINT64 CurrentFenceValue, PFNCreateNew pfnCreateNew, const CreationArgType&... CreationArgs) noexcept(false)
{
auto lock = m_pLock ? std::unique_lock(*m_pLock) : std::unique_lock<std::mutex>();
TPool::iterator Head = m_Pool.begin();
auto Head = m_Pool.begin();
if (Head == m_Pool.end() || (CurrentFenceValue < Head->first))
{
return std::move(pfnCreateNew(CreationArgs...)); // throw( _com_error )
Expand All @@ -54,7 +54,7 @@ class CFencePool
{
auto lock = m_pLock ? std::unique_lock(*m_pLock) : std::unique_lock<std::mutex>();

TPool::iterator Head = m_Pool.begin();
auto Head = m_Pool.begin();

if (Head == m_Pool.end() || (CurrentFenceValue < Head->first))
{
Expand Down Expand Up @@ -112,16 +112,16 @@ class CBoundedFencePool : public CFencePool<TResourceType>
template <typename PFNWaitForFenceValue, typename PFNCreateNew, typename... CreationArgType>
TResourceType RetrieveFromPool(UINT64 CurrentFenceValue, PFNWaitForFenceValue pfnWaitForFenceValue, PFNCreateNew pfnCreateNew, const CreationArgType&... CreationArgs) noexcept(false)
{
auto lock = m_pLock ? std::unique_lock(*m_pLock) : std::unique_lock<std::mutex>();
TPool::iterator Head = m_Pool.begin();
auto lock = this->m_pLock ? std::unique_lock(*this->m_pLock) : std::unique_lock<std::mutex>();
auto Head = this->m_Pool.begin();

if (Head == m_Pool.end())
if (Head == this->m_Pool.end())
{
return std::move(pfnCreateNew(CreationArgs...)); // throw( _com_error )
}
else if (CurrentFenceValue < Head->first)
{
if (m_Pool.size() < m_MaxInFlightDepth)
if (this->m_Pool.size() < m_MaxInFlightDepth)
{
return std::move(pfnCreateNew(CreationArgs...)); // throw( _com_error )
}
Expand All @@ -133,12 +133,12 @@ class CBoundedFencePool : public CFencePool<TResourceType>

assert(Head->second);
TResourceType ret = std::move(Head->second);
m_Pool.erase(Head);
this->m_Pool.erase(Head);
return std::move(ret);
}

CBoundedFencePool(bool bLock = false, UINT MaxInFlightDepth = UINT_MAX) noexcept
: CFencePool(bLock),
: CFencePool<TResourceType>(bLock),
m_MaxInFlightDepth(MaxInFlightDepth)
{
}
Expand All @@ -149,8 +149,8 @@ class CBoundedFencePool : public CFencePool<TResourceType>
}
CBoundedFencePool& operator=(CBoundedFencePool&& other) noexcept
{
m_Pool = std::move(other.m_Pool);
m_pLock = std::move(other.m_pLock);
this->m_Pool = std::move(other.m_Pool);
this->m_pLock = std::move(other.m_pLock);
m_MaxInFlightDepth = other.m_MaxInFlightDepth;
return *this;
}
Expand Down
35 changes: 18 additions & 17 deletions include/ImmediateContext.inl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ inline bool CViewBoundState<TBindable, NumBindSlots>::IsDirty(TDeclVector const&

if (!bDirty)
{
bDirty = DirtyBitsUpTo(static_cast<UINT>(rootSignatureBucketSize));
bDirty = this->DirtyBitsUpTo(static_cast<UINT>(rootSignatureBucketSize));
}

return bDirty;
Expand Down Expand Up @@ -954,6 +954,23 @@ inline void GetBufferViewDesc(Resource* pBuffer, TDesc& Desc, UINT APIOffset, UI
}
}

//----------------------------------------------------------------------------------------------------------------------------------
template<EShaderStage eShader> struct DescriptorBindFuncs
{
static decltype(&ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable) GetBindFunc()
{
return &ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable;
}
};
template<> struct DescriptorBindFuncs<e_CS>
{
static decltype(&ID3D12GraphicsCommandList::SetComputeRootDescriptorTable) GetBindFunc()
{
return &ID3D12GraphicsCommandList::SetComputeRootDescriptorTable;
}
};

//----------------------------------------------------------------------------------------------------------------------------------
template<EShaderStage eShader> struct SRVBindIndices;
template<> struct SRVBindIndices<e_PS> { static const UINT c_TableIndex = 1; };
template<> struct SRVBindIndices<e_VS> { static const UINT c_TableIndex = 4; };
Expand Down Expand Up @@ -1025,22 +1042,6 @@ inline void ImmediateContext::ApplySamplersHelper() noexcept
CurrentState.m_SamplerTableBase);
}

//----------------------------------------------------------------------------------------------------------------------------------
template<EShaderStage eShader> struct DescriptorBindFuncs
{
static decltype(&ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable) GetBindFunc()
{
return &ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable;
}
};
template<> struct DescriptorBindFuncs<e_CS>
{
static decltype(&ID3D12GraphicsCommandList::SetComputeRootDescriptorTable) GetBindFunc()
{
return &ID3D12GraphicsCommandList::SetComputeRootDescriptorTable;
}
};

//----------------------------------------------------------------------------------------------------------------------------------
inline void TRANSLATION_API ImmediateContext::Dispatch(UINT x, UINT y, UINT z)
{
Expand Down
2 changes: 1 addition & 1 deletion include/ResourceBinding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace D3D12TranslationLayer
CViewBoundState() noexcept(false)
: CBoundState<TBindable, NumBindSlots>()
{
m_ShaderData.reserve(NumBindings); // throw( bad_alloc )
m_ShaderData.reserve(this->NumBindings); // throw( bad_alloc )
}

bool UpdateBinding(_In_range_(0, NumBindings - 1) UINT slot, _In_opt_ TBindable* pBindable, EShaderStage stage) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion include/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace D3D12TranslationLayer

const TDesc12& GetDesc12() noexcept;

bool IsUpToDate() const noexcept { return m_pResource->GetUniqueness<TIface>() == m_ViewUniqueness; }
bool IsUpToDate() const noexcept;
HRESULT RefreshUnderlying() noexcept;
D3D12_CPU_DESCRIPTOR_HANDLE GetRefreshedDescriptorHandle()
{
Expand Down
9 changes: 8 additions & 1 deletion include/View.inl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace D3D12TranslationLayer
__if_exists(TDesc12::Buffer)
{
typedef decltype(TDesc12::Buffer) TBufferDesc12;
if (m_pResource->AppDesc()->ResourceDimension() == D3D11_RESOURCE_DIMENSION_BUFFER)
if (m_pResource->AppDesc()->ResourceDimension() == static_cast<int>(D3D11_RESOURCE_DIMENSION_BUFFER))
{
UINT Divisor = GetByteAlignment(m_Desc.Format);
__if_exists(TBufferDesc12::StructureByteStride)
Expand All @@ -107,6 +107,13 @@ namespace D3D12TranslationLayer
return m_Desc;
}

//----------------------------------------------------------------------------------------------------------------------------------
template<typename TIface>
bool View<TIface>::IsUpToDate() const noexcept
{
return m_pResource->GetUniqueness<TIface>() == m_ViewUniqueness;
}

//----------------------------------------------------------------------------------------------------------------------------------
template<typename TIface>
HRESULT View<TIface>::RefreshUnderlying() noexcept
Expand Down
8 changes: 4 additions & 4 deletions include/segmented_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ inline segmented_stack< T, segment_size, unary >::segmented_stack(const unary& n
template< class T, size_t segment_size, typename unary >
inline void segmented_stack< T, segment_size, unary >::free()
{
for (segment_vector::iterator segment = m_segments.begin(); segment != m_segments.end(); ++segment)
for (auto segment = m_segments.begin(); segment != m_segments.end(); ++segment)
{
for (segment_range::iterator it = segment->m_begin; it != segment->m_end; ++it)
for (auto it = segment->m_begin; it != segment->m_end; ++it)
{
it->~T();
}
Expand Down Expand Up @@ -324,9 +324,9 @@ inline void segmented_stack< T, segment_size, unary >::swap(segmented_stack< T,
template< class T, size_t segment_size, typename unary >
inline void segmented_stack< T, segment_size, unary >::clear()
{
for (segment_vector::iterator segment = m_segments.begin(); segment != m_segments.end(); ++segment)
for (auto segment = m_segments.begin(); segment != m_segments.end(); ++segment)
{
for (segment_range::iterator it = segment->m_begin; it != segment->m_end; ++it)
for (auto it = segment->m_begin; it != segment->m_end; ++it)
{
it->~T();
}
Expand Down
3 changes: 2 additions & 1 deletion src/BlitHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ namespace D3D12TranslationLayer
D3D12_GPU_DESCRIPTOR_HANDLE SRVBaseGPU = m_pParent->m_ViewHeap.GPUHandle(SRVBaseSlot);
pCommandList->SetGraphicsRootDescriptorTable(0, SRVBaseGPU);

pCommandList->OMSetRenderTargets(1, &pRTV->GetRefreshedDescriptorHandle(), TRUE, nullptr);
auto Descriptor = pRTV->GetRefreshedDescriptorHandle();
pCommandList->OMSetRenderTargets(1, &Descriptor, TRUE, nullptr);

// Constant buffers: srcRect, src dimensions
{
Expand Down
5 changes: 5 additions & 0 deletions src/DeviceChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace D3D12TranslationLayer
m_pParent->AddObjectToDeferredDeletionQueue(pObject, m_LastUsedCommandListID, m_bWaitForCompletionRequired);
}

UINT64 DeviceChild::GetCommandListID(COMMAND_LIST_TYPE CommandListType) noexcept
{
return m_pParent->GetCommandListID(CommandListType);
}

void BatchedDeviceChild::ProcessBatch()
{
m_Parent.ProcessBatch();
Expand Down
22 changes: 14 additions & 8 deletions src/ImmediateContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ void ImmediateContext::RefreshNonHeapBindings(UINT64 DirtyBits) noexcept
UINT numRTVs = m_CurrentState.m_RTVs.GetNumBound();
D3D12_CPU_DESCRIPTOR_HANDLE RTVDescriptors[ MaxRTVs ];
D3D12_CPU_DESCRIPTOR_HANDLE *pDSVDescriptor = nullptr;
D3D12_CPU_DESCRIPTOR_HANDLE DSVDescriptor;
m_CurrentState.m_RTVs.ResetDirty();

for (UINT i = 0; i < numRTVs; ++i)
Expand All @@ -771,7 +772,8 @@ void ImmediateContext::RefreshNonHeapBindings(UINT64 DirtyBits) noexcept
auto pDSV = m_CurrentState.m_DSVs.GetBound()[0];
if (pDSV)
{
pDSVDescriptor = &pDSV->GetRefreshedDescriptorHandle();
DSVDescriptor = pDSV->GetRefreshedDescriptorHandle();
pDSVDescriptor = &DSVDescriptor;
}

GetGraphicsCommandList()->OMSetRenderTargets(numRTVs, RTVDescriptors, false, pDSVDescriptor);
Expand Down Expand Up @@ -1420,8 +1422,8 @@ void TRANSLATION_API ImmediateContext::ClearDepthStencilView(DSV *pDSV, UINT Fla
}
m_ResourceStateManager.ApplyAllResourceTransitions();

static_assert(D3D11_CLEAR_DEPTH == D3D12_CLEAR_FLAG_DEPTH, "Casting flags");
static_assert(D3D11_CLEAR_STENCIL == D3D12_CLEAR_FLAG_STENCIL, "Casting flags");
static_assert(D3D11_CLEAR_DEPTH == static_cast<int>(D3D12_CLEAR_FLAG_DEPTH), "Casting flags");
static_assert(D3D11_CLEAR_STENCIL == static_cast<int>(D3D12_CLEAR_FLAG_STENCIL), "Casting flags");
auto Descriptor = pDSV->GetRefreshedDescriptorHandle();
GetGraphicsCommandList()->ClearDepthStencilView(Descriptor, static_cast<D3D12_CLEAR_FLAGS>(Flags), Depth, Stencil, NumRects, pRects);
PostRender(COMMAND_LIST_TYPE::GRAPHICS);
Expand Down Expand Up @@ -2473,8 +2475,8 @@ void ImmediateContext::CopyAndConvertSubresourceRegion(Resource* pDst, UINT DstS
{
// This is a buffer to buffer copy
// Special-case buffer to buffer copies
assert(Descs[0].pResource->AppDesc()->ResourceDimension() == D3D11_RESOURCE_DIMENSION_BUFFER &&
Descs[1].pResource->AppDesc()->ResourceDimension() == D3D11_RESOURCE_DIMENSION_BUFFER);
assert(Descs[0].pResource->AppDesc()->ResourceDimension() == static_cast<int>(D3D11_RESOURCE_DIMENSION_BUFFER) &&
Descs[1].pResource->AppDesc()->ResourceDimension() == static_cast<int>(D3D11_RESOURCE_DIMENSION_BUFFER));

UINT64 SrcOffset = pSrcBox->left + GetDynamicBufferOffset(pSrc);
UINT64 Size = pSrcBox->right - pSrcBox->left;
Expand Down Expand Up @@ -4980,6 +4982,7 @@ void TRANSLATION_API ImmediateContext::UnmapUnderlyingStaging(Resource* pResourc

if (pResource->GetFormatEmulation() == FormatEmulation::YV12)
{
D3D12_RANGE Range;
UINT MipIndex, PlaneIndex, ArrayIndex;
pResource->DecomposeSubresource(Subresource, MipIndex, ArrayIndex, PlaneIndex);

Expand Down Expand Up @@ -5017,10 +5020,12 @@ void TRANSLATION_API ImmediateContext::UnmapUnderlyingStaging(Resource* pResourc
}
}

pResource->GetUnderlyingResource()->Unmap(0, &pResource->GetSubresourceRange(Subresource));
Range = pResource->GetSubresourceRange(Subresource);
pResource->GetUnderlyingResource()->Unmap(0, &Range);
}

pResource->GetUnderlyingResource()->Unmap(0, &pResource->GetSubresourceRange(Subresource));
Range = pResource->GetSubresourceRange(Subresource);
pResource->GetUnderlyingResource()->Unmap(0, &Range);
}
else
{
Expand Down Expand Up @@ -5061,7 +5066,8 @@ void TRANSLATION_API ImmediateContext::UnmapUnderlyingStaging(Resource* pResourc
else if (pResource->GetFormatEmulation() != FormatEmulation::None)
{
assert(pResource->GetFormatEmulation() == FormatEmulation::YV12);
pResource->GetUnderlyingResource()->Unmap(0, &CD3DX12_RANGE(0, 0));
auto Range = CD3DX12_RANGE(0, 0);
pResource->GetUnderlyingResource()->Unmap(0, &Range);
}
pResource->m_FormatEmulationStagingData[Subresource].m_MapState = Resource::EmulatedFormatMapState::None;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace D3D12TranslationLayer
{
assert(createArgs.m_FormatEmulation == FormatEmulation::YV12 || createArgs.m_FormatEmulation == FormatEmulation::None);
if ( createArgs.m_appDesc.Usage() == RESOURCE_USAGE_STAGING
|| createArgs.m_appDesc.Usage() == D3D11_USAGE_DYNAMIC)
|| createArgs.m_appDesc.Usage() == static_cast<int>(D3D11_USAGE_DYNAMIC))
{
if (GetSubresourceMultiplier(createArgs) > 1)
{
Expand All @@ -123,7 +123,7 @@ namespace D3D12TranslationLayer
inline UINT GetSubresourcesForFormatEmulationStagingData(ResourceCreationArgs const& createArgs) noexcept
{
return ( ( createArgs.m_appDesc.Usage() == RESOURCE_USAGE_STAGING
|| createArgs.m_appDesc.Usage() == D3D11_USAGE_DYNAMIC)
|| createArgs.m_appDesc.Usage() == static_cast<int>(D3D11_USAGE_DYNAMIC))
&& ( GetSubresourceMultiplier(createArgs) > 1
|| createArgs.m_FormatEmulation != FormatEmulation::None)) ?
GetTotalSubresources(createArgs) : 0u;
Expand All @@ -138,7 +138,7 @@ namespace D3D12TranslationLayer

inline UINT GetSubresourcesForDynamicTexturePlaneData(ResourceCreationArgs const& createArgs) noexcept
{
return (createArgs.m_appDesc.Usage() == D3D11_USAGE_DYNAMIC) ?
return (createArgs.m_appDesc.Usage() == static_cast<int>(D3D11_USAGE_DYNAMIC)) ?
createArgs.m_appDesc.Subresources() / createArgs.m_appDesc.NonOpaquePlaneCount() : 0u;
}

Expand All @@ -154,8 +154,8 @@ namespace D3D12TranslationLayer
// We should refactor so that the desc doesn't change after construction...
return ((createArgs.m_desc12.Flags & D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS) != D3D12_RESOURCE_FLAG_NONE ||
createArgs.m_desc12.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) &&
(createArgs.m_appDesc.Usage() == D3D11_USAGE_DEFAULT ||
createArgs.m_appDesc.Usage() == D3D11_USAGE_IMMUTABLE);
(createArgs.m_appDesc.Usage() == static_cast<int>(D3D11_USAGE_DEFAULT) ||
createArgs.m_appDesc.Usage() == static_cast<int>(D3D11_USAGE_IMMUTABLE));
}

//----------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace D3D12TranslationLayer

// Default row-major textures are unsupported by D3D12 (except for cross-adapter), therefore
// they are emulated using buffers and should typically be handled similarly to staging textures.
if (m_effectiveUsage == D3D11_USAGE_DEFAULT &&
if (m_effectiveUsage == static_cast<int>(D3D11_USAGE_DEFAULT) &&
Parent()->ResourceDimension12() != D3D12_RESOURCE_DIMENSION_BUFFER &&
Parent()->ApiTextureLayout12() == D3D12_TEXTURE_LAYOUT_ROW_MAJOR)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SubresourceHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ namespace D3D12TranslationLayer
if (DSMode != ReadOrWrite)
{
bool bWritable = DSMode == WriteOnly;
bool bDepth = !(Desc.Flags & D3D11_DSV_READ_ONLY_DEPTH) == bWritable;
bool bStencil = !(Desc.Flags & D3D11_DSV_READ_ONLY_STENCIL) == bWritable;
bool bDepth = !(Desc.Flags & static_cast<int>(D3D11_DSV_READ_ONLY_DEPTH)) == bWritable;
bool bStencil = !(Desc.Flags & static_cast<int>(D3D11_DSV_READ_ONLY_STENCIL)) == bWritable;
m_BeginPlane = (bDepth ? 0 : 1);
m_EndPlane = (bStencil ? 2 : 1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/VideoDecodeStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ namespace D3D12TranslationLayer
CD3DX12_RANGE ReadRange(0, GetResultOffsetForIndex(m_ResultCount));
ThrowFailure(m_ResultBuffer.Map(0, &ReadRange, &pMappedData));

auto Unmap = MakeScopeExit([&]() { m_ResultBuffer.Unmap(0, &CD3DX12_RANGE(0,0)); });
auto Range = CD3DX12_RANGE(0, 0);
auto Unmap = MakeScopeExit([&]() { m_ResultBuffer.Unmap(0, &Range); });

// Determine the fence ID of the last completed
UINT64 lastCompletedFenceID = m_pParent->GetCompletedFenceValue(COMMAND_LIST_TYPE::VIDEO_DECODE);
Expand Down
Loading