mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-24 20:18:29 +00:00
GPU: Add SDL_CalculateGPUTextureFormatSize (#11146)
--------- Co-authored-by: Sam Lantinga <slouken@libsdl.org>
This commit is contained in:
@@ -2796,3 +2796,16 @@ void SDL_ReleaseGPUFence(
|
||||
device->driverData,
|
||||
fence);
|
||||
}
|
||||
|
||||
Uint32 SDL_CalculateGPUTextureFormatSize(
|
||||
SDL_GPUTextureFormat format,
|
||||
Uint32 width,
|
||||
Uint32 height,
|
||||
Uint32 depth_or_layer_count)
|
||||
{
|
||||
Uint32 blockWidth = Texture_GetBlockWidth(format);
|
||||
Uint32 blockHeight = Texture_GetBlockHeight(format);
|
||||
Uint32 blocksPerRow = (width + blockWidth - 1) / blockWidth;
|
||||
Uint32 blocksPerColumn = (height + blockHeight - 1) / blockHeight;
|
||||
return depth_or_layer_count * blocksPerRow * blocksPerColumn * SDL_GPUTextureFormatTexelBlockSize(format);
|
||||
}
|
||||
|
@@ -362,18 +362,6 @@ static inline Uint32 BytesPerRow(
|
||||
return blocksPerRow * SDL_GPUTextureFormatTexelBlockSize(format);
|
||||
}
|
||||
|
||||
static inline Sint32 BytesPerImage(
|
||||
Uint32 width,
|
||||
Uint32 height,
|
||||
SDL_GPUTextureFormat format)
|
||||
{
|
||||
Uint32 blockWidth = Texture_GetBlockWidth(format);
|
||||
Uint32 blockHeight = Texture_GetBlockHeight(format);
|
||||
Uint32 blocksPerRow = (width + blockWidth - 1) / blockWidth;
|
||||
Uint32 blocksPerColumn = (height + blockHeight - 1) / blockHeight;
|
||||
return blocksPerRow * blocksPerColumn * SDL_GPUTextureFormatTexelBlockSize(format);
|
||||
}
|
||||
|
||||
// GraphicsDevice Limits
|
||||
|
||||
#define MAX_TEXTURE_SAMPLERS_PER_STAGE 16
|
||||
|
@@ -1752,7 +1752,7 @@ static void METAL_UploadToTexture(
|
||||
copyFromBuffer:bufferContainer->activeBuffer->handle
|
||||
sourceOffset:source->offset
|
||||
sourceBytesPerRow:BytesPerRow(destination->w, textureContainer->header.info.format)
|
||||
sourceBytesPerImage:BytesPerImage(destination->w, destination->h, textureContainer->header.info.format)
|
||||
sourceBytesPerImage:SDL_CalculateGPUTextureFormatSize(textureContainer->header.info.format, destination->w, destination->h, destination->d)
|
||||
sourceSize:MTLSizeMake(destination->w, destination->h, destination->d)
|
||||
toTexture:metalTexture->handle
|
||||
destinationSlice:destination->layer
|
||||
|
Reference in New Issue
Block a user