mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-09 19:50:13 +02:00
Updated for latest D3DX12.h
This commit is contained in:
parent
06ca03e6bd
commit
a403767285
@ -2011,6 +2011,29 @@ inline void MemcpySubresource(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
// Row-by-row memcpy
|
||||||
|
inline void MemcpySubresource(
|
||||||
|
_In_ const D3D12_MEMCPY_DEST* pDest,
|
||||||
|
_In_ const void* pResourceData,
|
||||||
|
_In_ const D3D12_SUBRESOURCE_INFO* pSrc,
|
||||||
|
SIZE_T RowSizeInBytes,
|
||||||
|
UINT NumRows,
|
||||||
|
UINT NumSlices) noexcept
|
||||||
|
{
|
||||||
|
for (UINT z = 0; z < NumSlices; ++z)
|
||||||
|
{
|
||||||
|
auto pDestSlice = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
|
||||||
|
auto pSrcSlice = (static_cast<const BYTE*>(pResourceData) + pSrc->Offset) + pSrc->DepthPitch * LONG_PTR(z);
|
||||||
|
for (UINT y = 0; y < NumRows; ++y)
|
||||||
|
{
|
||||||
|
memcpy(pDestSlice + pDest->RowPitch * y,
|
||||||
|
pSrcSlice + pSrc->RowPitch * LONG_PTR(y),
|
||||||
|
RowSizeInBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// Returns required size of a buffer to be used for data upload
|
// Returns required size of a buffer to be used for data upload
|
||||||
inline UINT64 GetRequiredIntermediateSize(
|
inline UINT64 GetRequiredIntermediateSize(
|
||||||
@ -2087,6 +2110,65 @@ inline UINT64 UpdateSubresources(
|
|||||||
return RequiredSize;
|
return RequiredSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
// All arrays must be populated (e.g. by calling GetCopyableFootprints)
|
||||||
|
inline UINT64 UpdateSubresources(
|
||||||
|
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||||
|
_In_ ID3D12Resource* pDestinationResource,
|
||||||
|
_In_ ID3D12Resource* pIntermediate,
|
||||||
|
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||||
|
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||||
|
UINT64 RequiredSize,
|
||||||
|
_In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
|
||||||
|
_In_reads_(NumSubresources) const UINT* pNumRows,
|
||||||
|
_In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
|
||||||
|
_In_ const void* pResourceData,
|
||||||
|
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||||
|
{
|
||||||
|
// Minor validation
|
||||||
|
auto IntermediateDesc = pIntermediate->GetDesc();
|
||||||
|
auto DestinationDesc = pDestinationResource->GetDesc();
|
||||||
|
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
|
||||||
|
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
|
||||||
|
RequiredSize > SIZE_T(-1) ||
|
||||||
|
(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
|
||||||
|
(FirstSubresource != 0 || NumSubresources != 1)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BYTE* pData;
|
||||||
|
HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (UINT i = 0; i < NumSubresources; ++i)
|
||||||
|
{
|
||||||
|
if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
|
||||||
|
D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) };
|
||||||
|
MemcpySubresource(&DestData, pResourceData, &pSrcData[i], static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
|
||||||
|
}
|
||||||
|
pIntermediate->Unmap(0, nullptr);
|
||||||
|
|
||||||
|
if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||||
|
{
|
||||||
|
pCmdList->CopyBufferRegion(
|
||||||
|
pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (UINT i = 0; i < NumSubresources; ++i)
|
||||||
|
{
|
||||||
|
CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
|
||||||
|
CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
|
||||||
|
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RequiredSize;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// Heap-allocating UpdateSubresources implementation
|
// Heap-allocating UpdateSubresources implementation
|
||||||
inline UINT64 UpdateSubresources(
|
inline UINT64 UpdateSubresources(
|
||||||
@ -2099,7 +2181,7 @@ inline UINT64 UpdateSubresources(
|
|||||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
||||||
{
|
{
|
||||||
UINT64 RequiredSize = 0;
|
UINT64 RequiredSize = 0;
|
||||||
UINT64 MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
|
auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
|
||||||
if (MemToAlloc > SIZE_MAX)
|
if (MemToAlloc > SIZE_MAX)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -2110,8 +2192,8 @@ inline UINT64 UpdateSubresources(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
|
auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
|
||||||
UINT64* pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
|
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
|
||||||
UINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
|
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
|
||||||
|
|
||||||
auto Desc = pDestinationResource->GetDesc();
|
auto Desc = pDestinationResource->GetDesc();
|
||||||
ID3D12Device* pDevice = nullptr;
|
ID3D12Device* pDevice = nullptr;
|
||||||
@ -2124,6 +2206,44 @@ inline UINT64 UpdateSubresources(
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
// Heap-allocating UpdateSubresources implementation
|
||||||
|
inline UINT64 UpdateSubresources(
|
||||||
|
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||||
|
_In_ ID3D12Resource* pDestinationResource,
|
||||||
|
_In_ ID3D12Resource* pIntermediate,
|
||||||
|
UINT64 IntermediateOffset,
|
||||||
|
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||||
|
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||||
|
_In_ const void* pResourceData,
|
||||||
|
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||||
|
{
|
||||||
|
UINT64 RequiredSize = 0;
|
||||||
|
auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
|
||||||
|
if (MemToAlloc > SIZE_MAX)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
|
||||||
|
if (pMem == nullptr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
|
||||||
|
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
|
||||||
|
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
|
||||||
|
|
||||||
|
auto Desc = pDestinationResource->GetDesc();
|
||||||
|
ID3D12Device* pDevice = nullptr;
|
||||||
|
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||||
|
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
|
||||||
|
pDevice->Release();
|
||||||
|
|
||||||
|
UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pResourceData, pSrcData);
|
||||||
|
HeapFree(GetProcessHeap(), 0, pMem);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// Stack-allocating UpdateSubresources implementation
|
// Stack-allocating UpdateSubresources implementation
|
||||||
template <UINT MaxSubresources>
|
template <UINT MaxSubresources>
|
||||||
@ -2132,8 +2252,8 @@ inline UINT64 UpdateSubresources(
|
|||||||
_In_ ID3D12Resource* pDestinationResource,
|
_In_ ID3D12Resource* pDestinationResource,
|
||||||
_In_ ID3D12Resource* pIntermediate,
|
_In_ ID3D12Resource* pIntermediate,
|
||||||
UINT64 IntermediateOffset,
|
UINT64 IntermediateOffset,
|
||||||
_In_range_(0, MaxSubresources) UINT FirstSubresource,
|
_In_range_(0,MaxSubresources) UINT FirstSubresource,
|
||||||
_In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
|
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
|
||||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
||||||
{
|
{
|
||||||
UINT64 RequiredSize = 0;
|
UINT64 RequiredSize = 0;
|
||||||
@ -2150,6 +2270,33 @@ inline UINT64 UpdateSubresources(
|
|||||||
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
|
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
// Stack-allocating UpdateSubresources implementation
|
||||||
|
template <UINT MaxSubresources>
|
||||||
|
inline UINT64 UpdateSubresources(
|
||||||
|
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||||
|
_In_ ID3D12Resource* pDestinationResource,
|
||||||
|
_In_ ID3D12Resource* pIntermediate,
|
||||||
|
UINT64 IntermediateOffset,
|
||||||
|
_In_range_(0,MaxSubresources) UINT FirstSubresource,
|
||||||
|
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
|
||||||
|
_In_ const void* pResourceData,
|
||||||
|
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||||
|
{
|
||||||
|
UINT64 RequiredSize = 0;
|
||||||
|
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
|
||||||
|
UINT NumRows[MaxSubresources];
|
||||||
|
UINT64 RowSizesInBytes[MaxSubresources];
|
||||||
|
|
||||||
|
auto Desc = pDestinationResource->GetDesc();
|
||||||
|
ID3D12Device* pDevice = nullptr;
|
||||||
|
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||||
|
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
|
||||||
|
pDevice->Release();
|
||||||
|
|
||||||
|
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pResourceData, pSrcData);
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
inline constexpr bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout ) noexcept
|
inline constexpr bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout ) noexcept
|
||||||
{ return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
|
{ return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user