| 1219 | } |
| 1220 | |
| 1221 | ALResult Tr2TextureAL::CopySubresourceRegion( const Tr2TextureSubresource& destSubresource, Tr2TextureAL& source, const Tr2TextureSubresource& sourceSubresource, Tr2RenderContextAL& renderContext ) |
| 1222 | { |
| 1223 | if( !IsValid() ) |
| 1224 | { |
| 1225 | return E_INVALIDCALL; |
| 1226 | } |
| 1227 | if( !source.IsValid() || !renderContext.IsValid() ) |
| 1228 | { |
| 1229 | return E_INVALIDARG; |
| 1230 | } |
| 1231 | |
| 1232 | auto dstResource = GetResourceDx12(); |
| 1233 | auto srcResource = source.GetResourceDx12(); |
| 1234 | |
| 1235 | auto srcState = source.m_defaultState; |
| 1236 | renderContext.IsBoundDx12( source, srcState ); |
| 1237 | |
| 1238 | if( destSubresource.IsSubresourceFull( m_desc ) && sourceSubresource.IsSubresourceFull( source.m_desc ) ) |
| 1239 | { |
| 1240 | { |
| 1241 | D3D12_RESOURCE_BARRIER barriers[2] = { |
| 1242 | TrinityALImpl::Transition( srcResource, srcState, D3D12_RESOURCE_STATE_COPY_SOURCE ), |
| 1243 | TrinityALImpl::Transition( dstResource, m_defaultState, D3D12_RESOURCE_STATE_COPY_DEST ), |
| 1244 | }; |
| 1245 | renderContext.ResourceBarrierDx12( 2, barriers ); |
| 1246 | renderContext.FlushBarriersDx12( srcResource, dstResource ); |
| 1247 | } |
| 1248 | renderContext.m_commandList->CopyResource( dstResource, srcResource ); |
| 1249 | { |
| 1250 | D3D12_RESOURCE_BARRIER barriers[2] = { |
| 1251 | TrinityALImpl::Transition( srcResource, D3D12_RESOURCE_STATE_COPY_SOURCE, srcState ), |
| 1252 | TrinityALImpl::Transition( dstResource, D3D12_RESOURCE_STATE_COPY_DEST, m_defaultState ), |
| 1253 | }; |
| 1254 | renderContext.ResourceBarrierDx12( 2, barriers ); |
| 1255 | FlushBarriersMaybe( *this, source, renderContext ); |
| 1256 | } |
| 1257 | return S_OK; |
| 1258 | } |
| 1259 | |
| 1260 | |
| 1261 | Tr2TextureSubresource src = sourceSubresource; |
| 1262 | Tr2TextureSubresource dst = destSubresource; |
| 1263 | |
| 1264 | if( !Crop( src, source.m_desc, dst, m_desc ) ) |
| 1265 | { |
| 1266 | return E_FAIL; |
| 1267 | } |
| 1268 | |
| 1269 | D3D12_BOX box = { src.m_box.left, src.m_box.top, src.m_box.front, src.m_box.right, src.m_box.bottom, src.m_box.back }; |
| 1270 | |
| 1271 | const uint32_t srcMipCount = source.m_desc.GetTrueMipCount(); |
| 1272 | const uint32_t dstMipCount = m_desc.GetTrueMipCount(); |
| 1273 | |
| 1274 | const uint32_t mipCount = std::min( src.GetMipCount(), dst.GetMipCount() ); |
| 1275 | |
| 1276 | { |
| 1277 | D3D12_RESOURCE_BARRIER barriers[2] = { |
| 1278 | TrinityALImpl::Transition( srcResource, srcState, D3D12_RESOURCE_STATE_COPY_SOURCE ), |
no test coverage detected