@@ -5925,6 +5925,7 @@ static void D3D12_UploadToTexture(
59255925 Uint32 alignedRowPitch ;
59265926 Uint32 rowsPerSlice = source -> rows_per_layer ;
59275927 Uint32 bytesPerSlice ;
5928+ Uint32 alignedBytesPerSlice ;
59285929 bool needsRealignment ;
59295930 bool needsPlacementCopy ;
59305931
@@ -5962,10 +5963,13 @@ static void D3D12_UploadToTexture(
59625963
59635964 bytesPerSlice = rowsPerSlice * rowPitch ;
59645965
5965- alignedRowPitch = D3D12_INTERNAL_Align (rowPitch , D3D12_TEXTURE_DATA_PITCH_ALIGNMENT );
5966+ alignedRowPitch = BytesPerRow (destination -> w , textureContainer -> header .info .format );
5967+ alignedRowPitch = D3D12_INTERNAL_Align (alignedRowPitch , D3D12_TEXTURE_DATA_PITCH_ALIGNMENT );
59665968 needsRealignment = rowsPerSlice != destination -> h || rowPitch != alignedRowPitch ;
59675969 needsPlacementCopy = source -> offset % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT != 0 ;
59685970
5971+ alignedBytesPerSlice = alignedRowPitch * destination -> h ;
5972+
59695973 sourceLocation .Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT ;
59705974 sourceLocation .PlacedFootprint .Footprint .Format = SDLToD3D12_TextureFormat [textureContainer -> header .info .format ];
59715975 sourceLocation .PlacedFootprint .Footprint .RowPitch = alignedRowPitch ;
@@ -5990,22 +5994,25 @@ static void D3D12_UploadToTexture(
59905994
59915995 for (Uint32 sliceIndex = 0 ; sliceIndex < destination -> d ; sliceIndex += 1 ) {
59925996 // copy row count minus one to avoid overread
5993- for (Uint32 rowIndex = 0 ; rowIndex < rowsPerSlice - 1 ; rowIndex += 1 ) {
5997+ for (Uint32 rowIndex = 0 ; rowIndex < destination -> h - 1 ; rowIndex += 1 ) {
5998+
59945999 SDL_memcpy (
5995- temporaryBuffer -> mapPointer + (sliceIndex * rowsPerSlice ) + (rowIndex * alignedRowPitch ),
6000+ temporaryBuffer -> mapPointer + (sliceIndex * alignedBytesPerSlice ) + (rowIndex * alignedRowPitch ),
59966001 transferBufferContainer -> activeBuffer -> mapPointer + source -> offset + (sliceIndex * bytesPerSlice ) + (rowIndex * rowPitch ),
5997- rowPitch );
6002+ alignedRowPitch );
6003+
59986004 }
5999- Uint32 offset = source -> offset + (sliceIndex * bytesPerSlice ) + ((rowsPerSlice - 1 ) * rowPitch );
6005+ Uint32 offset = source -> offset + (sliceIndex * bytesPerSlice ) + ((destination -> h - 1 ) * rowPitch );
6006+
60006007 SDL_memcpy (
6001- temporaryBuffer -> mapPointer + (sliceIndex * rowsPerSlice ) + ((rowsPerSlice - 1 ) * alignedRowPitch ),
6008+ temporaryBuffer -> mapPointer + (sliceIndex * alignedBytesPerSlice ) + ((destination -> h - 1 ) * alignedRowPitch ),
60026009 transferBufferContainer -> activeBuffer -> mapPointer + offset ,
60036010 SDL_min (alignedRowPitch , transferBufferContainer -> size - offset ));
60046011
60056012 sourceLocation .PlacedFootprint .Footprint .Width = destination -> w ;
6006- sourceLocation .PlacedFootprint .Footprint .Height = rowsPerSlice ;
6013+ sourceLocation .PlacedFootprint .Footprint .Height = destination -> h ;
60076014 sourceLocation .PlacedFootprint .Footprint .Depth = 1 ;
6008- sourceLocation .PlacedFootprint .Offset = (sliceIndex * bytesPerSlice );
6015+ sourceLocation .PlacedFootprint .Offset = (sliceIndex * alignedBytesPerSlice );
60096016
60106017 ID3D12GraphicsCommandList_CopyTextureRegion (
60116018 d3d12CommandBuffer -> graphicsCommandList ,
@@ -6046,7 +6053,7 @@ static void D3D12_UploadToTexture(
60466053 sourceLocation .PlacedFootprint .Offset = 0 ;
60476054 sourceLocation .PlacedFootprint .Footprint .Width = destination -> w ;
60486055 sourceLocation .PlacedFootprint .Footprint .Height = destination -> h ;
6049- sourceLocation .PlacedFootprint .Footprint .Depth = 1 ;
6056+ sourceLocation .PlacedFootprint .Footprint .Depth = destination -> d ;
60506057
60516058 ID3D12GraphicsCommandList_CopyTextureRegion (
60526059 d3d12CommandBuffer -> graphicsCommandList ,
0 commit comments