|
30 | 30 | #include "DeviceContextD3D12Impl.hpp"
|
31 | 31 |
|
32 | 32 | #include <sstream>
|
| 33 | +#include <array> |
33 | 34 |
|
34 | 35 | #include "RenderDeviceD3D12Impl.hpp"
|
35 | 36 | #include "PipelineStateD3D12Impl.hpp"
|
@@ -1957,19 +1958,29 @@ void DeviceContextD3D12Impl::CopyTexture(const CopyTextureAttribs& CopyAttribs)
|
1957 | 1958 | pD3D12SrcBox = &D3D12SrcBox;
|
1958 | 1959 | }
|
1959 | 1960 |
|
1960 |
| - UINT DstSubResIndex = D3D12CalcSubresource(CopyAttribs.DstMipLevel, CopyAttribs.DstSlice, 0, DstTexDesc.MipLevels, DstTexDesc.GetArraySize()); |
1961 |
| - UINT SrcSubResIndex = D3D12CalcSubresource(CopyAttribs.SrcMipLevel, CopyAttribs.SrcSlice, 0, SrcTexDesc.MipLevels, SrcTexDesc.GetArraySize()); |
1962 |
| - CopyTextureRegion(pSrcTexD3D12, SrcSubResIndex, pD3D12SrcBox, CopyAttribs.SrcTextureTransitionMode, |
1963 |
| - pDstTexD3D12, DstSubResIndex, CopyAttribs.DstX, CopyAttribs.DstY, CopyAttribs.DstZ, |
| 1961 | + static constexpr Uint32 MaxFormatPlaneCount = 2; // Depth and stencil planes |
| 1962 | + std::array<SubresCopyMapping, MaxFormatPlaneCount> Planes; |
| 1963 | + |
| 1964 | + Uint32 NumPlanes = std::min(pSrcTexD3D12->GetFormatPlaneCount(), pDstTexD3D12->GetFormatPlaneCount()); |
| 1965 | + VERIFY(NumPlanes <= MaxFormatPlaneCount, "Number of planes (", NumPlanes, ") exceeds maximum supported plane count (", MaxFormatPlaneCount, ")"); |
| 1966 | + NumPlanes = std::min(NumPlanes, MaxFormatPlaneCount); |
| 1967 | + for (Uint32 i = 0; i < NumPlanes; ++i) |
| 1968 | + { |
| 1969 | + Planes[i].Dst = D3D12CalcSubresource(CopyAttribs.DstMipLevel, CopyAttribs.DstSlice, i, DstTexDesc.MipLevels, DstTexDesc.GetArraySize()); |
| 1970 | + Planes[i].Src = D3D12CalcSubresource(CopyAttribs.SrcMipLevel, CopyAttribs.SrcSlice, i, SrcTexDesc.MipLevels, SrcTexDesc.GetArraySize()); |
| 1971 | + } |
| 1972 | + CopyTextureRegion(pSrcTexD3D12, pD3D12SrcBox, CopyAttribs.SrcTextureTransitionMode, pDstTexD3D12, |
| 1973 | + Planes.data(), NumPlanes, |
| 1974 | + CopyAttribs.DstX, CopyAttribs.DstY, CopyAttribs.DstZ, |
1964 | 1975 | CopyAttribs.DstTextureTransitionMode);
|
1965 | 1976 | }
|
1966 | 1977 |
|
1967 | 1978 | void DeviceContextD3D12Impl::CopyTextureRegion(TextureD3D12Impl* pSrcTexture,
|
1968 |
| - Uint32 SrcSubResIndex, |
1969 | 1979 | const D3D12_BOX* pD3D12SrcBox,
|
1970 | 1980 | RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode,
|
1971 | 1981 | TextureD3D12Impl* pDstTexture,
|
1972 |
| - Uint32 DstSubResIndex, |
| 1982 | + const SubresCopyMapping* Planes, |
| 1983 | + Uint32 NumPlanes, |
1973 | 1984 | Uint32 DstX,
|
1974 | 1985 | Uint32 DstY,
|
1975 | 1986 | Uint32 DstZ,
|
@@ -1997,35 +2008,43 @@ void DeviceContextD3D12Impl::CopyTextureRegion(TextureD3D12Impl* pS
|
1997 | 2008 | }
|
1998 | 2009 | TransitionOrVerifyTextureState(CmdCtx, *pDstTexture, DstTextureTransitionMode, RESOURCE_STATE_COPY_DEST, "Using resource as copy destination (DeviceContextD3D12Impl::CopyTextureRegion)");
|
1999 | 2010 |
|
2000 |
| - D3D12_TEXTURE_COPY_LOCATION DstLocation = {}, SrcLocation = {}; |
| 2011 | + D3D12_TEXTURE_COPY_LOCATION DstLocation{}; |
| 2012 | + D3D12_TEXTURE_COPY_LOCATION SrcLocation{}; |
2001 | 2013 |
|
2002 | 2014 | SrcLocation.pResource = pSrcTexture->GetD3D12Resource();
|
2003 |
| - if (pSrcTexture->GetDesc().Usage == USAGE_STAGING) |
2004 |
| - { |
2005 |
| - SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; |
2006 |
| - SrcLocation.PlacedFootprint = pSrcTexture->GetStagingFootprint(SrcSubResIndex); |
2007 |
| - } |
2008 |
| - else |
2009 |
| - { |
2010 |
| - SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; |
2011 |
| - SrcLocation.SubresourceIndex = SrcSubResIndex; |
2012 |
| - } |
2013 |
| - |
2014 | 2015 | DstLocation.pResource = pDstTexture->GetD3D12Resource();
|
2015 |
| - if (pDstTexture->GetDesc().Usage == USAGE_STAGING) |
2016 |
| - { |
2017 |
| - DstLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; |
2018 |
| - DstLocation.PlacedFootprint = pDstTexture->GetStagingFootprint(DstSubResIndex); |
2019 |
| - } |
2020 |
| - else |
2021 |
| - { |
2022 |
| - DstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; |
2023 |
| - DstLocation.SubresourceIndex = DstSubResIndex; |
2024 |
| - } |
2025 | 2016 |
|
2026 | 2017 | CmdCtx.FlushResourceBarriers();
|
2027 |
| - CmdCtx.GetCommandList()->CopyTextureRegion(&DstLocation, DstX, DstY, DstZ, &SrcLocation, pD3D12SrcBox); |
2028 |
| - ++m_State.NumCommands; |
| 2018 | + |
| 2019 | + for (Uint32 plane = 0; plane < NumPlanes; ++plane) |
| 2020 | + { |
| 2021 | + Uint32 SrcSubResIndex = Planes[plane].Src; |
| 2022 | + Uint32 DstSubResIndex = Planes[plane].Dst; |
| 2023 | + if (pSrcTexture->GetDesc().Usage == USAGE_STAGING) |
| 2024 | + { |
| 2025 | + SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; |
| 2026 | + SrcLocation.PlacedFootprint = pSrcTexture->GetStagingFootprint(SrcSubResIndex); |
| 2027 | + } |
| 2028 | + else |
| 2029 | + { |
| 2030 | + SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; |
| 2031 | + SrcLocation.SubresourceIndex = SrcSubResIndex; |
| 2032 | + } |
| 2033 | + |
| 2034 | + if (pDstTexture->GetDesc().Usage == USAGE_STAGING) |
| 2035 | + { |
| 2036 | + DstLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; |
| 2037 | + DstLocation.PlacedFootprint = pDstTexture->GetStagingFootprint(DstSubResIndex); |
| 2038 | + } |
| 2039 | + else |
| 2040 | + { |
| 2041 | + DstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; |
| 2042 | + DstLocation.SubresourceIndex = DstSubResIndex; |
| 2043 | + } |
| 2044 | + |
| 2045 | + CmdCtx.GetCommandList()->CopyTextureRegion(&DstLocation, DstX, DstY, DstZ, &SrcLocation, pD3D12SrcBox); |
| 2046 | + ++m_State.NumCommands; |
| 2047 | + } |
2029 | 2048 | }
|
2030 | 2049 |
|
2031 | 2050 | void DeviceContextD3D12Impl::CopyTextureRegion(ID3D12Resource* pd3d12Buffer,
|
|
0 commit comments