diff --git a/include/Allocator.h b/include/Allocator.h index 9199cea..8ae14c4 100644 --- a/include/Allocator.h +++ b/include/Allocator.h @@ -2,6 +2,8 @@ // Licensed under the MIT License. #pragma once +#include "BlockAllocators.h" + namespace D3D12TranslationLayer { class HeapSuballocationBlock : public BlockAllocators::CGenericBlock diff --git a/include/BlockAllocators.h b/include/BlockAllocators.h index ae334b7..4ddce10 100644 --- a/include/BlockAllocators.h +++ b/include/BlockAllocators.h @@ -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(); }; diff --git a/include/DeviceChild.hpp b/include/DeviceChild.hpp index 897b3d7..2f2d8d4 100644 --- a/include/DeviceChild.hpp +++ b/include/DeviceChild.hpp @@ -64,7 +64,7 @@ namespace D3D12TranslationLayer template void AddToDeferredDeletionQueue(unique_comptr& spObject, COMMAND_LIST_TYPE CommandListType) { - AddToDeferredDeletionQueue(spObject, CommandListType, m_pParent->GetCommandListID(CommandListType)); + AddToDeferredDeletionQueue(spObject, CommandListType, GetCommandListID(CommandListType)); } void SwapIdentities(DeviceChild& Other) @@ -78,6 +78,7 @@ namespace D3D12TranslationLayer } void AddToDeferredDeletionQueue(ID3D12Object* pObject); + UINT64 GetCommandListID(COMMAND_LIST_TYPE CommandListType) const; }; template @@ -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(); } diff --git a/include/ImmediateContext.hpp b/include/ImmediateContext.hpp index ad459f8..cd6d5d6 100644 --- a/include/ImmediateContext.hpp +++ b/include/ImmediateContext.hpp @@ -2,10 +2,16 @@ // Licensed under the MIT License. #pragma once +#include "Allocator.h" +#include "Resource.hpp" +#include "Util.hpp" + namespace D3D12TranslationLayer { -class Resource; class CommandListManager; +class Resource; +class ResourceCache; +class ViewBase; struct TranslationLayerCallbacks { @@ -38,7 +44,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(); - 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 ) @@ -54,7 +60,7 @@ class CFencePool { auto lock = m_pLock ? std::unique_lock(*m_pLock) : std::unique_lock(); - TPool::iterator Head = m_Pool.begin(); + auto Head = m_Pool.begin(); if (Head == m_Pool.end() || (CurrentFenceValue < Head->first)) { @@ -586,7 +592,11 @@ enum EDirtyBits : UINT64 e_ReassertOnNewCommandList = e_GraphicsStateDirty | e_ComputeStateDirty, }; +class Fence; +class HeapSuballocationBlock; class ImmediateContext; +struct DeferredWait; +struct ResidencyManagedObjectWrapper; struct RetiredObject { diff --git a/include/ImmediateContext.inl b/include/ImmediateContext.inl index b658d94..511f830 100644 --- a/include/ImmediateContext.inl +++ b/include/ImmediateContext.inl @@ -265,7 +265,7 @@ inline bool CViewBoundState::IsDirty(TDeclVector const& if (!bDirty) { - bDirty = DirtyBitsUpTo(static_cast(New.size())); + bDirty = this->DirtyBitsUpTo(static_cast(New.size())); } if (bDirty) @@ -944,6 +944,40 @@ template<> struct SRVBindIndices { static const UINT c_TableIndex = 10; }; template<> struct SRVBindIndices { static const UINT c_TableIndex = 13; }; template<> struct SRVBindIndices { static const UINT c_TableIndex = 1; }; +//---------------------------------------------------------------------------------------------------------------------------------- +template struct CBBindIndices; +template<> struct CBBindIndices { static const UINT c_TableIndex = 0; }; +template<> struct CBBindIndices { static const UINT c_TableIndex = 3; }; +template<> struct CBBindIndices { static const UINT c_TableIndex = 6; }; +template<> struct CBBindIndices { static const UINT c_TableIndex = 9; }; +template<> struct CBBindIndices { static const UINT c_TableIndex = 12; }; +template<> struct CBBindIndices { static const UINT c_TableIndex = 0; }; + +//---------------------------------------------------------------------------------------------------------------------------------- +template struct SamplerBindIndices; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 2; }; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 5; }; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 8; }; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 11; }; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 14; }; +template<> struct SamplerBindIndices { static const UINT c_TableIndex = 2; }; + +//---------------------------------------------------------------------------------------------------------------------------------- +template struct DescriptorBindFuncs +{ + static decltype(&ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable) GetBindFunc() + { + return &ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable; + } +}; +template<> struct DescriptorBindFuncs +{ + static decltype(&ID3D12GraphicsCommandList::SetComputeRootDescriptorTable) GetBindFunc() + { + return &ID3D12GraphicsCommandList::SetComputeRootDescriptorTable; + } +}; + template inline void ImmediateContext::ApplyShaderResourcesHelper() noexcept { @@ -959,15 +993,6 @@ inline void ImmediateContext::ApplyShaderResourcesHelper() noexcept CurrentState.m_SRVTableBase); } -//---------------------------------------------------------------------------------------------------------------------------------- -template struct CBBindIndices; -template<> struct CBBindIndices { static const UINT c_TableIndex = 0; }; -template<> struct CBBindIndices { static const UINT c_TableIndex = 3; }; -template<> struct CBBindIndices { static const UINT c_TableIndex = 6; }; -template<> struct CBBindIndices { static const UINT c_TableIndex = 9; }; -template<> struct CBBindIndices { static const UINT c_TableIndex = 12; }; -template<> struct CBBindIndices { static const UINT c_TableIndex = 0; }; - template inline void ImmediateContext::ApplyConstantBuffersHelper() noexcept { @@ -983,15 +1008,6 @@ inline void ImmediateContext::ApplyConstantBuffersHelper() noexcept CurrentState.m_CBTableBase); } -//---------------------------------------------------------------------------------------------------------------------------------- -template struct SamplerBindIndices; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 2; }; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 5; }; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 8; }; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 11; }; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 14; }; -template<> struct SamplerBindIndices { static const UINT c_TableIndex = 2; }; - template inline void ImmediateContext::ApplySamplersHelper() noexcept { @@ -1007,22 +1023,6 @@ inline void ImmediateContext::ApplySamplersHelper() noexcept CurrentState.m_SamplerTableBase); } -//---------------------------------------------------------------------------------------------------------------------------------- -template struct DescriptorBindFuncs -{ - static decltype(&ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable) GetBindFunc() - { - return &ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable; - } -}; -template<> struct DescriptorBindFuncs -{ - static decltype(&ID3D12GraphicsCommandList::SetComputeRootDescriptorTable) GetBindFunc() - { - return &ID3D12GraphicsCommandList::SetComputeRootDescriptorTable; - } -}; - //---------------------------------------------------------------------------------------------------------------------------------- inline void TRANSLATION_API ImmediateContext::Dispatch(UINT x, UINT y, UINT z) { diff --git a/include/Resource.hpp b/include/Resource.hpp index 17d7d58..4ab5965 100644 --- a/include/Resource.hpp +++ b/include/Resource.hpp @@ -2,8 +2,17 @@ // Licensed under the MIT License. #pragma once +#include "ResourceState.hpp" + namespace D3D12TranslationLayer { + enum class ShaderResourceViewType; + enum class RenderTargetViewType; + enum class DepthStencilViewType; + enum class UnorderedAccessViewType; + enum class VideoDecoderOutputViewType; + enum class VideoProcessorInputViewType; + enum class VideoProcessorOutputViewType; // The same as D3D11 enum RESOURCE_USAGE diff --git a/include/ResourceBinding.hpp b/include/ResourceBinding.hpp index a655fe8..e7c441c 100644 --- a/include/ResourceBinding.hpp +++ b/include/ResourceBinding.hpp @@ -2,6 +2,9 @@ // Licensed under the MIT License. #pragma once +#include "Sampler.hpp" +#include "Shader.hpp" + namespace D3D12TranslationLayer { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -243,7 +246,7 @@ namespace D3D12TranslationLayer CViewBoundState() noexcept(false) : CBoundState() { - 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; diff --git a/include/ResourceState.hpp b/include/ResourceState.hpp index d3774d3..30b4c11 100644 --- a/include/ResourceState.hpp +++ b/include/ResourceState.hpp @@ -2,9 +2,12 @@ // Licensed under the MIT License. #pragma once +#include "ResourceBinding.hpp" + namespace D3D12TranslationLayer { class CommandListManager; + class Fence; // These are defined in the private d3d12 header #define UNKNOWN_RESOURCE_STATE (D3D12_RESOURCE_STATES)0x8000u diff --git a/include/Sampler.hpp b/include/Sampler.hpp index 33593ec..5c24e66 100644 --- a/include/Sampler.hpp +++ b/include/Sampler.hpp @@ -2,6 +2,8 @@ // Licensed under the MIT License. #pragma once +#include "DeviceChild.hpp" + namespace D3D12TranslationLayer { //================================================================================================================================== diff --git a/include/Shader.hpp b/include/Shader.hpp index 36b53a7..57f3d2d 100644 --- a/include/Shader.hpp +++ b/include/Shader.hpp @@ -2,6 +2,8 @@ // Licensed under the MIT License. #pragma once +#include "DeviceChild.hpp" + namespace D3D12TranslationLayer { enum class RESOURCE_DIMENSION diff --git a/include/Util.hpp b/include/Util.hpp index cd54bd6..8785a77 100644 --- a/include/Util.hpp +++ b/include/Util.hpp @@ -345,11 +345,11 @@ namespace D3D12TranslationLayer return reinterpret_cast(this); } - using unique_ptr::release; - using unique_ptr::get; - using unique_ptr::operator->; - using unique_ptr::operator*; - using unique_ptr::operator bool; + using std::unique_ptr::release; + using std::unique_ptr::get; + using std::unique_ptr::operator->; + using std::unique_ptr::operator*; + using std::unique_ptr::operator bool; private: unique_comptr& operator=(unique_comptr const&) = delete; diff --git a/include/View.hpp b/include/View.hpp index 343ad12..ddf8681 100644 --- a/include/View.hpp +++ b/include/View.hpp @@ -125,7 +125,7 @@ namespace D3D12TranslationLayer const TDesc12& GetDesc12() noexcept; - bool IsUpToDate() const noexcept { return m_pResource->GetUniqueness() == m_ViewUniqueness; } + bool IsUpToDate() const noexcept; HRESULT RefreshUnderlying() noexcept; D3D12_CPU_DESCRIPTOR_HANDLE GetRefreshedDescriptorHandle() { diff --git a/include/View.inl b/include/View.inl index a18b0b6..fce63a2 100644 --- a/include/View.inl +++ b/include/View.inl @@ -3,269 +3,276 @@ #pragma once namespace D3D12TranslationLayer { - template<> - inline void View::UpdateMinLOD(float MinLOD) - { - switch (m_Desc.ViewDimension) - { - case D3D12_SRV_DIMENSION_BUFFER: - case D3D12_SRV_DIMENSION_TEXTURE2DMS: - case D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY: - break; - case D3D12_SRV_DIMENSION_TEXTURE1D: - m_Desc.Texture1D.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURE1DARRAY: - m_Desc.Texture1DArray.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURE2D: - m_Desc.Texture2D.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURE2DARRAY: - m_Desc.Texture2DArray.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURE3D: - m_Desc.Texture3D.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURECUBE: - m_Desc.TextureCube.ResourceMinLODClamp = MinLOD; - break; - case D3D12_SRV_DIMENSION_TEXTURECUBEARRAY: - m_Desc.TextureCubeArray.ResourceMinLODClamp = MinLOD; - break; - } - } + template<> + inline void View::UpdateMinLOD(float MinLOD) + { + switch (m_Desc.ViewDimension) + { + case D3D12_SRV_DIMENSION_BUFFER: + case D3D12_SRV_DIMENSION_TEXTURE2DMS: + case D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY: + break; + case D3D12_SRV_DIMENSION_TEXTURE1D: + m_Desc.Texture1D.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURE1DARRAY: + m_Desc.Texture1DArray.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURE2D: + m_Desc.Texture2D.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURE2DARRAY: + m_Desc.Texture2DArray.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURE3D: + m_Desc.Texture3D.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURECUBE: + m_Desc.TextureCube.ResourceMinLODClamp = MinLOD; + break; + case D3D12_SRV_DIMENSION_TEXTURECUBEARRAY: + m_Desc.TextureCubeArray.ResourceMinLODClamp = MinLOD; + break; + } + } - template< class TIface > - inline void View::UpdateMinLOD(float /*MinLOD*/) - { - // Do nothing - } + template< class TIface > + inline void View::UpdateMinLOD(float /*MinLOD*/) + { + // Do nothing + } - //---------------------------------------------------------------------------------------------------------------------------------- - inline UINT GetDynamicBufferOffset(Resource* pBuffer) - { - UINT64 offset = pBuffer ? pBuffer->GetSubresourcePlacement(0).Offset : 0; - assert(offset < (UINT)-1); // D3D11 resources shouldn't be able to produce offsetable buffers of more than UINT_MAX - return (UINT)offset; - } + //---------------------------------------------------------------------------------------------------------------------------------- + inline UINT GetDynamicBufferOffset(Resource* pBuffer) + { + UINT64 offset = pBuffer ? pBuffer->GetSubresourcePlacement(0).Offset : 0; + assert(offset < (UINT)-1); // D3D11 resources shouldn't be able to produce offsetable buffers of more than UINT_MAX + return (UINT)offset; + } - template - inline UINT GetDynamicBufferSize(Resource* pBuffer, UINT offset) - { - UINT width = pBuffer->GetSubresourcePlacement(0).Footprint.Width; - return offset > width ? 0 : width - offset; - } + template + inline UINT GetDynamicBufferSize(Resource* pBuffer, UINT offset) + { + UINT width = pBuffer->GetSubresourcePlacement(0).Footprint.Width; + return offset > width ? 0 : width - offset; + } - template<> - inline UINT GetDynamicBufferSize(Resource* pBuffer, UINT offset) - { - UINT pitch = pBuffer->GetSubresourcePlacement(0).Footprint.RowPitch; - return offset > pitch ? 0 : pitch - offset; - } + template<> + inline UINT GetDynamicBufferSize(Resource* pBuffer, UINT offset) + { + UINT pitch = pBuffer->GetSubresourcePlacement(0).Footprint.RowPitch; + return offset > pitch ? 0 : pitch - offset; + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - void View::ViewBound(UINT slot, EShaderStage stage) noexcept - { - m_currentBindings.ViewBound(stage, slot); - m_pResource->ViewBound(this, stage, slot); - m_pParent->TransitionResourceForBindings(this); - } + //---------------------------------------------------------------------------------------------------------------------------------- + template + void View::ViewBound(UINT slot, EShaderStage stage) noexcept + { + m_currentBindings.ViewBound(stage, slot); + m_pResource->ViewBound(this, stage, slot); + m_pParent->TransitionResourceForBindings(this); + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - void View::ViewUnbound(UINT slot, EShaderStage stage) noexcept - { - m_currentBindings.ViewUnbound(stage, slot); - m_pResource->ViewUnbound(this, stage, slot); - m_pParent->TransitionResourceForBindings(this); - } + //---------------------------------------------------------------------------------------------------------------------------------- + template + void View::ViewUnbound(UINT slot, EShaderStage stage) noexcept + { + m_currentBindings.ViewUnbound(stage, slot); + m_pResource->ViewUnbound(this, stage, slot); + m_pParent->TransitionResourceForBindings(this); + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - typename const View::TDesc12& View::GetDesc12() noexcept - { - __if_exists(TDesc12::Buffer) - { - typedef decltype(TDesc12::Buffer) TBufferDesc12; - if (m_pResource->AppDesc()->ResourceDimension() == D3D11_RESOURCE_DIMENSION_BUFFER) - { - UINT Divisor = GetByteAlignment(m_Desc.Format); - __if_exists(TBufferDesc12::StructureByteStride) - { - if (m_Desc.Buffer.StructureByteStride != 0) - { - Divisor = m_Desc.Buffer.StructureByteStride; - } - } - UINT ByteOffset = GetDynamicBufferOffset(m_pResource); - assert(ByteOffset % Divisor == 0); - m_Desc.Buffer.FirstElement = APIFirstElement + ByteOffset / Divisor; - } - } - return m_Desc; - } + //---------------------------------------------------------------------------------------------------------------------------------- + template + typename const View::TDesc12& View::GetDesc12() noexcept + { + __if_exists(TDesc12::Buffer) + { + typedef decltype(TDesc12::Buffer) TBufferDesc12; + if (m_pResource->AppDesc()->ResourceDimension() == D3D11_RESOURCE_DIMENSION_BUFFER) + { + UINT Divisor = GetByteAlignment(m_Desc.Format); + __if_exists(TBufferDesc12::StructureByteStride) + { + if (m_Desc.Buffer.StructureByteStride != 0) + { + Divisor = m_Desc.Buffer.StructureByteStride; + } + } + UINT ByteOffset = GetDynamicBufferOffset(m_pResource); + assert(ByteOffset % Divisor == 0); + m_Desc.Buffer.FirstElement = APIFirstElement + ByteOffset / Divisor; + } + } + return m_Desc; + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - HRESULT View::RefreshUnderlying() noexcept - { - if (m_ViewUniqueness != m_pResource->GetUniqueness()) - { - UpdateMinLOD(m_pResource->GetMinLOD()); + //---------------------------------------------------------------------------------------------------------------------------------- + template + typename bool View::IsUpToDate() const noexcept + { + return m_pResource->GetUniqueness() == m_ViewUniqueness; + } - const TDesc12 &Desc = GetDesc12(); - (m_pParent->m_pDevice12.get()->*CViewMapper::GetCreate())( - m_pResource->GetUnderlyingResource(), - &Desc, - m_Descriptor); + //---------------------------------------------------------------------------------------------------------------------------------- + template + HRESULT View::RefreshUnderlying() noexcept + { + if (m_ViewUniqueness != m_pResource->GetUniqueness()) + { + UpdateMinLOD(m_pResource->GetMinLOD()); - m_ViewUniqueness = m_pResource->GetUniqueness(); - return S_OK; - } - return S_FALSE; - } + const TDesc12& Desc = GetDesc12(); + (m_pParent->m_pDevice12.get()->*CViewMapper::GetCreate())( + m_pResource->GetUnderlyingResource(), + &Desc, + m_Descriptor); - //---------------------------------------------------------------------------------------------------------------------------------- - // Specialized because ID3D12Device::CreateUnorderedAccessView takes 2 resources as input - template<> - inline HRESULT View::RefreshUnderlying() noexcept - { - // UAVs are always refreshed (to ensure that the proper counter resource is passed in) - UAV* p11on12UAV = static_cast(this); - const TDesc12 &Desc = GetDesc12(); + m_ViewUniqueness = m_pResource->GetUniqueness(); + return S_OK; + } + return S_FALSE; + } - m_pParent->m_pDevice12.get()->CreateUnorderedAccessView( - m_pResource->GetUnderlyingResource(), - p11on12UAV->m_pCounterResource.get(), - &Desc, - m_Descriptor - ); + //---------------------------------------------------------------------------------------------------------------------------------- + // Specialized because ID3D12Device::CreateUnorderedAccessView takes 2 resources as input + template<> + inline HRESULT View::RefreshUnderlying() noexcept + { + // UAVs are always refreshed (to ensure that the proper counter resource is passed in) + UAV* p11on12UAV = static_cast(this); + const TDesc12& Desc = GetDesc12(); - m_ViewUniqueness = m_pResource->GetUniqueness(); - return S_OK; - } + m_pParent->m_pDevice12.get()->CreateUnorderedAccessView( + m_pResource->GetUnderlyingResource(), + p11on12UAV->m_pCounterResource.get(), + &Desc, + m_Descriptor + ); - //---------------------------------------------------------------------------------------------------------------------------------- - // Specialized because no underlying D3D12 video views - template<> - inline HRESULT View::RefreshUnderlying() noexcept - { - m_ViewUniqueness = m_pResource->GetUniqueness(); - return S_OK; - } + m_ViewUniqueness = m_pResource->GetUniqueness(); + return S_OK; + } - template<> - inline HRESULT View::RefreshUnderlying() noexcept - { - m_ViewUniqueness = m_pResource->GetUniqueness(); - return S_OK; - } + //---------------------------------------------------------------------------------------------------------------------------------- + // Specialized because no underlying D3D12 video views + template<> + inline HRESULT View::RefreshUnderlying() noexcept + { + m_ViewUniqueness = m_pResource->GetUniqueness(); + return S_OK; + } - template<> - inline HRESULT View::RefreshUnderlying() noexcept - { - m_ViewUniqueness = m_pResource->GetUniqueness(); - return S_OK; - } + template<> + inline HRESULT View::RefreshUnderlying() noexcept + { + m_ViewUniqueness = m_pResource->GetUniqueness(); + return S_OK; + } - //---------------------------------------------------------------------------------------------------------------------------------- - inline ViewBase::ViewBase(ImmediateContext* pDevice, Resource* pResource, CViewSubresourceSubset const& Subresources) noexcept - : DeviceChild(pDevice) - , m_pResource(pResource) - , m_ViewUniqueness(UINT_MAX) - , m_subresources(Subresources) - { - } + template<> + inline HRESULT View::RefreshUnderlying() noexcept + { + m_ViewUniqueness = m_pResource->GetUniqueness(); + return S_OK; + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - View::View(ImmediateContext* pDevice, const typename TDesc12 &Desc, Resource &ViewResource) noexcept(false) - : ViewBase(pDevice, - &ViewResource, - CViewSubresourceSubset(Desc, - (UINT8)ViewResource.AppDesc()->MipLevels(), - (UINT16)ViewResource.AppDesc()->ArraySize(), - (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount() * ViewResource.SubresourceMultiplier())), - m_Desc(Desc), - m_BindRefs(0), - APIFirstElement(0) - { - __if_exists(TDesc12::Buffer) - { - APIFirstElement = Desc.Buffer.FirstElement; - } + //---------------------------------------------------------------------------------------------------------------------------------- + inline ViewBase::ViewBase(ImmediateContext* pDevice, Resource* pResource, CViewSubresourceSubset const& Subresources) noexcept + : DeviceChild(pDevice) + , m_pResource(pResource) + , m_ViewUniqueness(UINT_MAX) + , m_subresources(Subresources) + { + } - m_Descriptor = pDevice->GetViewAllocator().AllocateHeapSlot(&m_DescriptorHeapIndex); // throw( _com_error ) - } + //---------------------------------------------------------------------------------------------------------------------------------- + template + View::View(ImmediateContext* pDevice, const typename TDesc12& Desc, Resource& ViewResource) noexcept(false) + : ViewBase(pDevice, + &ViewResource, + CViewSubresourceSubset(Desc, + (UINT8)ViewResource.AppDesc()->MipLevels(), + (UINT16)ViewResource.AppDesc()->ArraySize(), + (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount()* ViewResource.SubresourceMultiplier())), + m_Desc(Desc), + m_BindRefs(0), + APIFirstElement(0) + { + __if_exists(TDesc12::Buffer) + { + APIFirstElement = Desc.Buffer.FirstElement; + } - //---------------------------------------------------------------------------------------------------------------------------------- - template - View::~View() noexcept - { - m_pParent->GetViewAllocator().FreeHeapSlot(m_Descriptor, m_DescriptorHeapIndex); - } + m_Descriptor = pDevice->GetViewAllocator().AllocateHeapSlot(&m_DescriptorHeapIndex); // throw( _com_error ) + } - //---------------------------------------------------------------------------------------------------------------------------------- - // Specialized because no underlying D3D12 video views - template<> - inline View::View(ImmediateContext* pDevice, const typename TDesc12 &Desc, Resource &ViewResource) noexcept(false) - : ViewBase(pDevice, - &ViewResource, - CViewSubresourceSubset(Desc, - (UINT8)ViewResource.AppDesc()->MipLevels(), - (UINT16)ViewResource.AppDesc()->ArraySize(), - (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount() * ViewResource.SubresourceMultiplier())), - m_Desc(Desc), - m_BindRefs(0) - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + template + View::~View() noexcept + { + m_pParent->GetViewAllocator().FreeHeapSlot(m_Descriptor, m_DescriptorHeapIndex); + } - //---------------------------------------------------------------------------------------------------------------------------------- - template<> - inline View::~View() noexcept - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + // Specialized because no underlying D3D12 video views + template<> + inline View::View(ImmediateContext* pDevice, const typename TDesc12& Desc, Resource& ViewResource) noexcept(false) + : ViewBase(pDevice, + &ViewResource, + CViewSubresourceSubset(Desc, + (UINT8)ViewResource.AppDesc()->MipLevels(), + (UINT16)ViewResource.AppDesc()->ArraySize(), + (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount()* ViewResource.SubresourceMultiplier())), + m_Desc(Desc), + m_BindRefs(0) + { + } - //---------------------------------------------------------------------------------------------------------------------------------- - template<> - inline View::View(ImmediateContext* pDevice, const typename TDesc12 &Desc, Resource &ViewResource) noexcept(false) - : ViewBase(pDevice, - &ViewResource, - CViewSubresourceSubset(Desc, - (UINT8)ViewResource.AppDesc()->MipLevels(), - (UINT16)ViewResource.AppDesc()->ArraySize(), - (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount() * ViewResource.SubresourceMultiplier())), - m_Desc(Desc), - m_BindRefs(0) - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + template<> + inline View::~View() noexcept + { + } - //---------------------------------------------------------------------------------------------------------------------------------- - template<> - inline View::~View() noexcept - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + template<> + inline View::View(ImmediateContext* pDevice, const typename TDesc12& Desc, Resource& ViewResource) noexcept(false) + : ViewBase(pDevice, + &ViewResource, + CViewSubresourceSubset(Desc, + (UINT8)ViewResource.AppDesc()->MipLevels(), + (UINT16)ViewResource.AppDesc()->ArraySize(), + (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount()* ViewResource.SubresourceMultiplier())), + m_Desc(Desc), + m_BindRefs(0) + { + } - //---------------------------------------------------------------------------------------------------------------------------------- - template<> - inline View::View(ImmediateContext* pDevice, const typename TDesc12 &Desc, Resource &ViewResource) noexcept(false) - : ViewBase(pDevice, - &ViewResource, - CViewSubresourceSubset(Desc, - (UINT8)ViewResource.AppDesc()->MipLevels(), - (UINT16)ViewResource.AppDesc()->ArraySize(), - (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount() * ViewResource.SubresourceMultiplier())), - m_Desc(Desc), - m_BindRefs(0) - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + template<> + inline View::~View() noexcept + { + } - //---------------------------------------------------------------------------------------------------------------------------------- - template<> - inline View::~View() noexcept - { - } + //---------------------------------------------------------------------------------------------------------------------------------- + template<> + inline View::View(ImmediateContext* pDevice, const typename TDesc12& Desc, Resource& ViewResource) noexcept(false) + : ViewBase(pDevice, + &ViewResource, + CViewSubresourceSubset(Desc, + (UINT8)ViewResource.AppDesc()->MipLevels(), + (UINT16)ViewResource.AppDesc()->ArraySize(), + (UINT8)ViewResource.AppDesc()->NonOpaquePlaneCount()* ViewResource.SubresourceMultiplier())), + m_Desc(Desc), + m_BindRefs(0) + { + } + + //---------------------------------------------------------------------------------------------------------------------------------- + template<> + inline View::~View() noexcept + { + } }; \ No newline at end of file diff --git a/include/segmented_stack.h b/include/segmented_stack.h index 469a2f3..96008b0 100644 --- a/include/segmented_stack.h +++ b/include/segmented_stack.h @@ -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(); } @@ -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(); } diff --git a/src/DeviceChild.cpp b/src/DeviceChild.cpp index 0def05c..00e194c 100644 --- a/src/DeviceChild.cpp +++ b/src/DeviceChild.cpp @@ -13,4 +13,9 @@ namespace D3D12TranslationLayer { m_Parent.ProcessBatch(); } -}; \ No newline at end of file + + UINT64 DeviceChild::GetCommandListID(COMMAND_LIST_TYPE CommandListType) const + { + return m_pParent->GetCommandListID(CommandListType); + } +}