Skip to content

Commit

Permalink
D3D12 texture upload over-read fix (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut authored Aug 20, 2024
1 parent 33478fd commit f928c12
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gpu/d3d12/SDL_gpu_d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -5204,12 +5204,18 @@ static void D3D12_UploadToTexture(
sourceLocation.pResource = temporaryBuffer->handle;

for (Uint32 sliceIndex = 0; sliceIndex < destination->d; sliceIndex += 1) {
for (Uint32 rowIndex = 0; rowIndex < rowsPerSlice; rowIndex += 1) {
/* copy row count minus one to avoid overread */
for (Uint32 rowIndex = 0; rowIndex < rowsPerSlice - 1; rowIndex += 1) {
SDL_memcpy(
temporaryBuffer->mapPointer + (sliceIndex * rowsPerSlice) + (rowIndex * alignedRowPitch),
transferBufferContainer->activeBuffer->mapPointer + source->offset + (sliceIndex * bytesPerSlice) + (rowIndex * rowPitch),
alignedRowPitch);
}
Uint32 offset = source->offset + (sliceIndex * bytesPerSlice) + ((rowsPerSlice - 1) * rowPitch);
SDL_memcpy(
temporaryBuffer->mapPointer + (sliceIndex * rowsPerSlice) + ((rowsPerSlice - 1) * alignedRowPitch),
transferBufferContainer->activeBuffer->mapPointer + offset,
SDL_min(alignedRowPitch, transferBufferContainer->size - offset));

sourceLocation.PlacedFootprint.Footprint.Width = destination->w;
sourceLocation.PlacedFootprint.Footprint.Height = rowsPerSlice;
Expand Down

0 comments on commit f928c12

Please sign in to comment.