mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-12-07 11:51:37 +08:00
Fix crash in UploadToTexture() on DX12.
(cherry picked from commit ab67be7e5a)
This commit is contained in:
committed by
Sam Lantinga
parent
df145a9649
commit
eb5eb4a33d
@@ -5884,6 +5884,7 @@ static void D3D12_UploadToTexture(
|
||||
Uint32 alignedRowPitch;
|
||||
Uint32 rowsPerSlice = source->rows_per_layer;
|
||||
Uint32 bytesPerSlice;
|
||||
Uint32 alignedBytesPerSlice;
|
||||
bool needsRealignment;
|
||||
bool needsPlacementCopy;
|
||||
|
||||
@@ -5921,10 +5922,13 @@ static void D3D12_UploadToTexture(
|
||||
|
||||
bytesPerSlice = rowsPerSlice * rowPitch;
|
||||
|
||||
alignedRowPitch = D3D12_INTERNAL_Align(rowPitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
|
||||
alignedRowPitch = BytesPerRow(destination->w, textureContainer->header.info.format);
|
||||
alignedRowPitch = D3D12_INTERNAL_Align(alignedRowPitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
|
||||
needsRealignment = rowsPerSlice != destination->h || rowPitch != alignedRowPitch;
|
||||
needsPlacementCopy = source->offset % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT != 0;
|
||||
|
||||
alignedBytesPerSlice = alignedRowPitch * destination->h;
|
||||
|
||||
sourceLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||
sourceLocation.PlacedFootprint.Footprint.Format = SDLToD3D12_TextureFormat[textureContainer->header.info.format];
|
||||
sourceLocation.PlacedFootprint.Footprint.RowPitch = alignedRowPitch;
|
||||
@@ -5949,22 +5953,25 @@ static void D3D12_UploadToTexture(
|
||||
|
||||
for (Uint32 sliceIndex = 0; sliceIndex < destination->d; sliceIndex += 1) {
|
||||
// copy row count minus one to avoid overread
|
||||
for (Uint32 rowIndex = 0; rowIndex < rowsPerSlice - 1; rowIndex += 1) {
|
||||
for (Uint32 rowIndex = 0; rowIndex < destination->h - 1; rowIndex += 1) {
|
||||
|
||||
SDL_memcpy(
|
||||
temporaryBuffer->mapPointer + (sliceIndex * rowsPerSlice) + (rowIndex * alignedRowPitch),
|
||||
temporaryBuffer->mapPointer + (sliceIndex * alignedBytesPerSlice) + (rowIndex * alignedRowPitch),
|
||||
transferBufferContainer->activeBuffer->mapPointer + source->offset + (sliceIndex * bytesPerSlice) + (rowIndex * rowPitch),
|
||||
rowPitch);
|
||||
alignedRowPitch);
|
||||
|
||||
}
|
||||
Uint32 offset = source->offset + (sliceIndex * bytesPerSlice) + ((rowsPerSlice - 1) * rowPitch);
|
||||
Uint32 offset = source->offset + (sliceIndex * bytesPerSlice) + ((destination->h - 1) * rowPitch);
|
||||
|
||||
SDL_memcpy(
|
||||
temporaryBuffer->mapPointer + (sliceIndex * rowsPerSlice) + ((rowsPerSlice - 1) * alignedRowPitch),
|
||||
temporaryBuffer->mapPointer + (sliceIndex * alignedBytesPerSlice) + ((destination->h - 1) * alignedRowPitch),
|
||||
transferBufferContainer->activeBuffer->mapPointer + offset,
|
||||
SDL_min(alignedRowPitch, transferBufferContainer->size - offset));
|
||||
|
||||
sourceLocation.PlacedFootprint.Footprint.Width = destination->w;
|
||||
sourceLocation.PlacedFootprint.Footprint.Height = rowsPerSlice;
|
||||
sourceLocation.PlacedFootprint.Footprint.Height = destination->h;
|
||||
sourceLocation.PlacedFootprint.Footprint.Depth = 1;
|
||||
sourceLocation.PlacedFootprint.Offset = (sliceIndex * bytesPerSlice);
|
||||
sourceLocation.PlacedFootprint.Offset = (sliceIndex * alignedBytesPerSlice);
|
||||
|
||||
ID3D12GraphicsCommandList_CopyTextureRegion(
|
||||
d3d12CommandBuffer->graphicsCommandList,
|
||||
@@ -6001,7 +6008,7 @@ static void D3D12_UploadToTexture(
|
||||
sourceLocation.PlacedFootprint.Offset = 0;
|
||||
sourceLocation.PlacedFootprint.Footprint.Width = destination->w;
|
||||
sourceLocation.PlacedFootprint.Footprint.Height = destination->h;
|
||||
sourceLocation.PlacedFootprint.Footprint.Depth = 1;
|
||||
sourceLocation.PlacedFootprint.Footprint.Depth = destination->d;
|
||||
|
||||
ID3D12GraphicsCommandList_CopyTextureRegion(
|
||||
d3d12CommandBuffer->graphicsCommandList,
|
||||
|
||||
Reference in New Issue
Block a user