Skip to content

Commit

Permalink
GPU: Add SDL_CalculateGPUTextureFormatSize
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed Oct 10, 2024
1 parent da5a158 commit ee481a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
17 changes: 17 additions & 0 deletions include/SDL3/SDL_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3715,6 +3715,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 w width in pixels.
* \param h height in pixels.
* \param d depth in pixels.
* \returns the size of a texture with this format and dimensions.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_CalculateGPUTextureFormatSize(
SDL_GPUTextureFormat format,
Uint32 w,
Uint32 h,
Uint32 d);

#ifdef SDL_PLATFORM_GDK

/**
Expand Down
13 changes: 13 additions & 0 deletions src/gpu/SDL_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,3 +2796,16 @@ void SDL_ReleaseGPUFence(
device->driverData,
fence);
}

Uint32 SDL_CalculateGPUTextureFormatSize(
SDL_GPUTextureFormat format,
Uint32 w,
Uint32 h,
Uint32 d)
{
Uint32 pixelRowsPerBlock = Texture_GetBlockSize(format);
Uint32 pixelColumnsPerBlock = pixelRowsPerBlock;
Uint32 blocksPerRow = (w + pixelRowsPerBlock - 1) / pixelRowsPerBlock;
Uint32 blocksPerColumn = (h + pixelColumnsPerBlock - 1) / pixelColumnsPerBlock;
return d * blocksPerRow * blocksPerColumn * SDL_GPUTextureFormatTexelBlockSize(format);
}
15 changes: 0 additions & 15 deletions src/gpu/SDL_sysgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,6 @@ static inline Uint32 BytesPerRow(
return blocksPerRow * SDL_GPUTextureFormatTexelBlockSize(format);
}

static inline Sint32 BytesPerImage(
Uint32 width,
Uint32 height,
SDL_GPUTextureFormat format)
{
Uint32 blocksPerRow = width;
Uint32 blocksPerColumn = height;
Uint32 pixelRowsPerBlock = Texture_GetBlockSize(format);
Uint32 pixelColumnsPerBlock = pixelRowsPerBlock;

blocksPerRow = (width + pixelRowsPerBlock - 1) / pixelRowsPerBlock;
blocksPerColumn = (height + pixelColumnsPerBlock - 1) / pixelColumnsPerBlock;
return blocksPerRow * blocksPerColumn * SDL_GPUTextureFormatTexelBlockSize(format);
}

// GraphicsDevice Limits

#define MAX_TEXTURE_SAMPLERS_PER_STAGE 16
Expand Down

0 comments on commit ee481a3

Please sign in to comment.