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

[Regression (again)] Metal YUV rendering broken on Intel MacOS #10006

Closed
olekolek1000 opened this issue Jun 11, 2024 · 15 comments
Closed

[Regression (again)] Metal YUV rendering broken on Intel MacOS #10006

olekolek1000 opened this issue Jun 11, 2024 · 15 comments
Milestone

Comments

@olekolek1000
Copy link
Contributor

olekolek1000 commented Jun 11, 2024

I was going to report a very similar YUV format issue related to internal webcam capture on MacOS (green tint and double vision), but on the way I encountered this:

Untitled

It's probably highly related to the resolved issue I reported before: issue

Steps to reproduce: Run testcamera on Intel Macbook (2015 in this case). MacOS 12.7.2 (the newest one available for this hardware)

@olekolek1000
Copy link
Contributor Author

Bisecting (again)...

@olekolek1000
Copy link
Contributor Author

olekolek1000 commented Jun 11, 2024

It is quite difficult to bisect testcamera, I tried to pinpoint which commit started causing this problem, but due to various failures in some older commits (SIGABRT crash, compilation errors etc), I couldn't do that reliably.

@slouken slouken added this to the 3.2.0 milestone Jun 11, 2024
@slouken
Copy link
Collaborator

slouken commented Jun 11, 2024

I ran testcamera on an Intel MacBook 2019, running macOS 14.5, and it worked with no issues.

Does everything except testcamera work? If so, what are the inputs and outputs to the CoreMediaFormatToSDL() function?

@icculus
Copy link
Collaborator

icculus commented Jun 11, 2024

Just to be clear, this is happening if you explicitly use the software renderer and not OpenGL or Metal?

@olekolek1000
Copy link
Contributor Author

Yes, tested testdrawchessboard and testgeometry, both run without any issues.
I've hooked up a printf() just under CoreMediaFormatToSDL() in GatherCameraSpecs function, it prints out these formats:
SDL_PIXELFORMAT_YUY2
SDL_PIXELFORMAT_UYVY
SDL_PIXELFORMAT_NV12
SDL_PIXELFORMAT_YUY2
SDL_PIXELFORMAT_UYVY
SDL_PIXELFORMAT_NV12
SDL_PIXELFORMAT_YUY2
SDL_PIXELFORMAT_UYVY
SDL_PIXELFORMAT_NV12

@olekolek1000
Copy link
Contributor Author

Just to be clear, this is happening if you explicitly use the software renderer and not OpenGL or Metal?

Let me check, one moment

@olekolek1000
Copy link
Contributor Author

Just to be clear, this is happening if you explicitly use the software renderer and not OpenGL or Metal?

Yup, that's it!
SDL_RENDER_DRIVER software and opengl works as intended, Metal is broken.

Texture renders correctly now (when it comes to the display itself, the color space of the camera is a different issue that I was originally going to report):
Untitled

@olekolek1000
Copy link
Contributor Author

testdrawchessboard and testgeometry both work OK on this laptop, in all three video backends (metal, gl, software).

@slouken
Copy link
Collaborator

slouken commented Jun 11, 2024

Yes, tested testdrawchessboard and testgeometry, both run without any issues. I've hooked up a printf() just under CoreMediaFormatToSDL() in GatherCameraSpecs function, it prints out these formats: SDL_PIXELFORMAT_YUY2 SDL_PIXELFORMAT_UYVY SDL_PIXELFORMAT_NV12 SDL_PIXELFORMAT_YUY2 SDL_PIXELFORMAT_UYVY SDL_PIXELFORMAT_NV12 SDL_PIXELFORMAT_YUY2 SDL_PIXELFORMAT_UYVY SDL_PIXELFORMAT_NV12

Do you know which of these formats is actually used when you're getting frames from the camera?

@olekolek1000
Copy link
Contributor Author

Do you know which of these formats is actually used when you're getting frames from the camera?

SDL_PIXELFORMAT_UYVY, grabbed from next_frame just below SDL_AcquireCameraFrame()

@olekolek1000 olekolek1000 changed the title [Regression (again)] Software rendering broken on Intel MacOS (non-HDR) [Regression (again)] Metal rendering broken on Intel MacOS (non-HDR) Jun 11, 2024
@olekolek1000 olekolek1000 changed the title [Regression (again)] Metal rendering broken on Intel MacOS (non-HDR) [Regression (again)] Metal YUV rendering broken on Intel MacOS Jun 11, 2024
@icculus
Copy link
Collaborator

icculus commented Jun 11, 2024

SDL_PIXELFORMAT_UYVY

The Metal renderer doesn't support this format, so it's something in the fallback code (GetClosestSupportedFormat or something down the line from that in SDL_CreateTextureWithProperties) that's probably blowing up.

@slouken
Copy link
Collaborator

slouken commented Jun 11, 2024

Yeah, I tested with testyuv --uyvy and it worked with the metal renderer, so this needs more investigation.

@slouken
Copy link
Collaborator

slouken commented Jun 12, 2024

I was able to reproduce this. There were two problems. The first is that we were trying to use a YUV shader with an RGB texture, which caused the graphical corruption and occasional crash. The second is that we were using default frame output settings, which converted the YUVY frame to NV12.

@icculus
Copy link
Collaborator

icculus commented Jun 12, 2024

which converted the YUVY frame to NV12.

Oh, I think Sylvain mentioned something about how Apple was giving NV12 data when you ask for YUVY data in the original pull request...! Mystery solved!

@1bsyl
Copy link
Contributor

1bsyl commented Jun 13, 2024

yes, indeed something gets fixed. Previous SDL3 version didn't work on macosx for me with an external camera, and now that's ok.

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

4 participants