Skip to content

CompressedTextures example fails assertion in Metal #73

@certik

Description

@certik

When running the CompressedTextures example on macOS, in the build directory:

$ make && ./SDL_gpu_examples
[...]
[  2%] Building C object CMakeFiles/SDL_gpu_examples.dir/Examples/CompressedTextures.c.o
[  5%] Linking C executable SDL_gpu_examples
[100%] Built target SDL_gpu_examples
2025-10-25 17:17:03.232 SDL_gpu_examples[20138:33017644] Welcome to the SDL_GPU example suite!
2025-10-25 17:17:03.232 SDL_gpu_examples[20138:33017644] Press A/D (or LB/RB) to move between examples!
2025-10-25 17:17:03.238 SDL_gpu_examples[20138:33017644] STARTING EXAMPLE: ClearScreen
2025-10-25 17:17:03.239 SDL_gpu_examples[20138:33017644] Metal API Validation Enabled
2025-10-25 17:17:07.601 SDL_gpu_examples[20138:33017644] STARTING EXAMPLE: CompressedTextures
-[MTLDebugBlitCommandEncoder validateCopyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:]:806: failed assertion `Copy From Buffer Validation
totalBytesUsed(17888) must be <= [sourceBuffer length](16384).
'

This can be fixed by:

--- a/Examples/CompressedTextures.c
+++ b/Examples/CompressedTextures.c
@@ -1,7 +1,7 @@
 #include "Common.h"

 #define BC_IMAGE_COUNT 12
-#define ASTC_IMAGE_COUNT 14
+#define ASTC_IMAGE_COUNT 13

 static SDL_GPUTexture* SrcTextures[BC_IMAGE_COUNT + ASTC_IMAGE_COUNT];
 static SDL_GPUTexture* DstTextures[BC_IMAGE_COUNT + ASTC_IMAGE_COUNT];
@@ -32,7 +32,7 @@ static SDL_GPUTextureFormat TextureFormats[BC_IMAGE_COUNT + ASTC_IMAGE_COUNT] =
        SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM,
        SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM,
        SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM,
-       SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM,
+       //SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM,
        SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM,
        SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM,
        SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM,

Probably the image size returned by the ASTC reader is incorrect for this particular case.

With this workaround every example works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions