Skip to content

Commit

Permalink
GPU: Add SDL_CalculateGPUTextureFormatSize
Browse files Browse the repository at this point in the history
Update include/SDL3/SDL_gpu.h

Co-authored-by: Sam Lantinga <[email protected]>
  • Loading branch information
thatcosmonaut and slouken committed Oct 10, 2024
1 parent 3db10a6 commit 1e12805
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions include/SDL3/SDL_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,23 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GPUTextureSupportsSampleCount(
SDL_GPUTextureFormat format,
SDL_GPUSampleCount sample_count);

/**
* Calculate the size in bytes of a texture format with dimensions.
*
* \param format a texture format.
* \param width width in pixels.
* \param height height in pixels.
* \param depth depth in pixels.
* \returns the size of a texture with this format and dimensions.
*
* \since This function is available since SDL 3.1.5.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_CalculateGPUTextureFormatSize(
SDL_GPUTextureFormat format,
Uint32 width,
Uint32 height,
Uint32 depth);

#ifdef SDL_PLATFORM_GDK

/**
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ SDL3_0.0.0 {
SDL_wcstol;
SDL_StepBackUTF8;
SDL_DelayPrecise;
SDL_CalculateGPUTextureFormatSize;
# extra symbols go here (don't modify this line)
local: *;
};
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,4 @@
#define SDL_wcstol SDL_wcstol_REAL
#define SDL_StepBackUTF8 SDL_StepBackUTF8_REAL
#define SDL_DelayPrecise SDL_DelayPrecise_REAL
#define SDL_CalculateGPUTextureFormatSize SDL_CalculateGPUTextureFormatSize_REAL
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,4 @@ SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),r
SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(Uint32,SDL_StepBackUTF8,(const char *a, const char **b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_DelayPrecise,(Uint64 a),(a),)
SDL_DYNAPI_PROC(Uint32,SDL_CalculateGPUTextureFormatSize,(SDL_GPUTextureFormat a, Uint32 b, Uint32 c, Uint32 d),(a,b,c,d),return)
9 changes: 9 additions & 0 deletions src/gpu/SDL_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,3 +2796,12 @@ void SDL_ReleaseGPUFence(
device->driverData,
fence);
}

Uint32 SDL_CalculateGPUTextureFormatSize(
SDL_GPUTextureFormat format,
Uint32 width,
Uint32 height,
Uint32 depth)
{
return depth * BytesPerImage(width, height, format);
}
2 changes: 1 addition & 1 deletion src/gpu/metal/SDL_gpu_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e12805

Please sign in to comment.