From 32f9c098d597dd29a9cb8cb5d0b5fd6fcc50aca4 Mon Sep 17 00:00:00 2001
From: Evan Hemsley <[EMAIL REDACTED]>
Date: Thu, 29 Oct 2026 09:34:44 -0700
Subject: [PATCH] Metal: Respect pixels_per_row and rows_per_layer on texture
upload
---
src/gpu/metal/SDL_gpu_metal.m | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m
index 9677e276d61f9..6562eacd5c2ad 100644
--- a/src/gpu/metal/SDL_gpu_metal.m
+++ b/src/gpu/metal/SDL_gpu_metal.m
@@ -1817,12 +1817,15 @@ static void METAL_UploadToTexture(
MetalTexture *metalTexture = METAL_INTERNAL_PrepareTextureForWrite(renderer, textureContainer, cycle);
+ Uint32 pixelsPerRow = source->pixels_per_row == 0 ? destination->w : source->pixels_per_row;
+ Uint32 rowsPerLayer = source->rows_per_layer == 0 ? destination->h : source->rows_per_layer;
+
[metalCommandBuffer->blitEncoder
copyFromBuffer:bufferContainer->activeBuffer->handle
sourceOffset:source->offset
- sourceBytesPerRow:BytesPerRow(destination->w, textureContainer->header.info.format)
+ sourceBytesPerRow:BytesPerRow(pixelsPerRow, textureContainer->header.info.format)
// sourceBytesPerImage expects the stride between 2D images (slices) of a 3D texture, not the size of the entire region
- sourceBytesPerImage:SDL_CalculateGPUTextureFormatSize(textureContainer->header.info.format, destination->w, destination->h, 1)
+ sourceBytesPerImage:SDL_CalculateGPUTextureFormatSize(textureContainer->header.info.format, pixelsPerRow, rowsPerLayer, 1)
sourceSize:MTLSizeMake(destination->w, destination->h, destination->d)
toTexture:metalTexture->handle
destinationSlice:destination->layer