Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3, MacOS: pixel formats using SDL_PIXELTYPE_ARRAYF16 and SDL_PIXELTYPE_ARRAYF32 result in metal api validation error #11727

Open
doraorak opened this issue Dec 26, 2024 · 3 comments
Assignees
Milestone

Comments

@doraorak
Copy link

doraorak commented Dec 26, 2024

-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5782: failed assertion
'Draw Errors Validation
Fragment Function (SDL_Advanced_fragment): missing buffer binding at index 1 for decode[0]'

below code is an easy way to reproduce on m3 14'' MacBook Pro. size of the buffer and the stride is acquired from CoreVideo framework for the pixel format kCVPixelFormatType_64RGBAHalf width 1512 height 982. even though below code isn't meant to display meaningful visuals, i can replicate the issue with a real pixel buffer, it shows distorted and broken colored version of the expected output when I use SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 64, 8) but gives the aforementioned error when I use SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 64, 8) or the pre-defined FLOAT formats. I am @kopyaçekmiyorum on SDL discord incase it may be needed.

#import <SDL3/SDL.h>
#import <SDL3/SDL_Main.h>
#include <stdlib.h>

int main(void) {
    SDL_Window* win;
    SDL_Renderer* ren;
    SDL_CreateWindowAndRenderer("win", 1512, 982, 0, &win, &ren);
    
    void* pb = malloc(11943936);
    memset(pb, 'abcd', 11943936);
    
    SDL_Surface* sur = SDL_CreateSurfaceFrom(1512, 982, SDL_PIXELFORMAT_RGBA64_FLOAT, pb, 12160);//SDL_PIXELFORMAT_RGBA64_FLOAT
    SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, sur);
    
    SDL_Event ev;
    int run = 1;
    while(run){
        while (SDL_PollEvent(&ev)) {
                    if (ev.type == SDL_EVENT_QUIT) {
                        run = 0;
                    }
            
                }
        SDL_RenderTexture(ren, tex, NULL, NULL);
        SDL_RenderPresent(ren);
    }
}
@doraorak
Copy link
Author

Workaround: you can disable metal api validation from your schemes diagnostics settings

@slouken slouken added this to the 3.2.0 milestone Dec 26, 2024
@doraorak doraorak changed the title SDL3, MacOS: pixel formats using SDL_PIXELTYPE_ARRAYF16 and SDL_PIXELTYPE_ARRAYF32 result in error SDL3, MacOS: pixel formats using SDL_PIXELTYPE_ARRAYF16 and SDL_PIXELTYPE_ARRAYF32 result in metal api validation error Dec 26, 2024
@slouken
Copy link
Collaborator

slouken commented Dec 26, 2024

@TheSpydog, can you look at this? I can repro, but I don't see anything obviously wrong in the shader constants or texture setup.

@doraorak
Copy link
Author

doraorak commented Dec 27, 2024

@TheSpydog, can you look at this? I can repro, but I don't see anything obviously wrong in the shader constants or texture setup.

I am not very experienced like you guys but for what its worth i think its because of the conditions here

if (texturedata.yuv || texturedata.nv12) {
because we will not be assigning the buffer as SDL_HAVE_YUV won't be defined and conditions aren't true anyway. But i still don't understand why it only happens with float formats. Maybe float formats somehow have the advanced fragment function while other formats have copy fragment function ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants