picoe / Eto.Veldrid

Veldrid control for Eto.Forms
MIT License
15 stars 6 forks source link

Metal backend only draws the pink background (mojave, intel 620) #1

Closed philstopford closed 5 years ago

philstopford commented 5 years ago

Testing this under macOS 10.14.4 on a Hackintosh (i7-7600U), I only get the pink background for the metal backend. Vulkan throws an exception; OpenGL works fine.

Just reporting in case this might be an issue in the implementation.

ItEndsWithTens commented 5 years ago

Thanks for trying this out! I appreciate you taking the time.

Regarding Vulkan, as I understand things macOS doesn't support it natively, and only something like MoltenVK would allow applications to use it. I don't know how that project would interact with Eto or Veldrid, assuming it's even possible, so the exception is something I'd expect to see.

As for Metal, I think the problem was a simple oversight about shader coordinates: according to the Veldrid docs, Metal uses the same clip space coordinate system as Direct3D 11. I was applying the Y coordinate inversion to the latter, but not the former. I've pushed a quick fix to master, if you'd like to try it out. There may be yet further issues, but I do believe commit 3ff1bb0 is necessary regardless.

Incidentally, this is why I changed the clear color from the tutorial example's black; with black I wouldn't be confident a render context was even up and running, whereas with pink the code is obviously able to at least set the viewport color.

It's also occurred to me I have an iPod touch that I think supports Metal, and a family member has a new iPhone, so maybe with some work I'll eventually be able to test this stuff myself. Fingers crossed I can figure out some sort of mobile testbed.

philstopford commented 5 years ago

Sadly, that doesn't appear to have helped - I still have a pink background.

ItEndsWithTens commented 5 years ago

Could I pester you to try out the Getting Started project from the veldrid-samples repository? I'll keep poking around my code, but in the meantime I think it'd be a good sanity check to ensure that one runs properly, since this project uses more or less the same approach to rendering.

philstopford commented 5 years ago

The getting started example from that repository builds and runs without issue here.

ItEndsWithTens commented 5 years ago

Excellent, thank you. I think I see where I'm going wrong; something about how I changed my code from the tutorial example is throwing me off. For now I think it might be safest just to do things the way the tutorial did, with the added step of requesting each backend use a consistent Y axis and depth range, instead of trying to handle it in the shader during the cross compile.

Before I commit my changes to master, would you mind checking out the new fix_metal_backend branch I just pushed? There's a commit that might do the trick, if we're lucky.

philstopford commented 5 years ago

Still just a pink background, for some odd reason.

ItEndsWithTens commented 5 years ago

Hmm. I'll have to mull this over for a bit, I'm stumped as to what else I could be doing wrong.

ItEndsWithTens commented 5 years ago

I'm in the process of fighting to get a Hackintosh up and running so I can test things myself, but until such time as I can swing that, could I ask you what happens if, in the fix_metal_backend branch, you comment out lines 167 and 168 in VeldridSurface.cs?

philstopford commented 5 years ago

Pink background

ItEndsWithTens commented 5 years ago

This will be a disappointing comment in the short term, I know, but I'm excited and wanted to tell someone: I've successfully configured a Hackintosh to dual boot on my usual desktop PC hardware, which supports Metal. Took me a couple days of fiddling, but it's finally up and running (I'm commenting from it right now, with a big dumb smile on my face), so I've now got myself testbed environments for all Veldrid backends! Except Vulkan in Linux, but we don't need to worry about that right now. :D

I've successfully reproduced your report (my OpenGL works fine but Metal is all pink), and I'll get on hacking away at the problem post haste.

philstopford commented 5 years ago

Congratulations. It's not always easy to get the Hackintosh environment installed (and stable), but it's surprisingly rewarding when it's done. All power to your elbow re. Metal.

Once I get some time and energy, I want to work on digging in to the code to understand how I can break out the buffers to allow similar configuration and use to etoViewport. I'm hoping it will be in the next month or so.

ItEndsWithTens commented 5 years ago

Okay! It's been a roundabout process, with one detour leading to another (I got four or five deep before all was said and done), but I think Metal works as of commit 501e7bf. At least it does on my DIY High Sierra machine, with any luck you'll find the same.

I've ignored my changes from the fix_metal_backend branch, since the PreferX clip space and depth range options aren't always available, whereas the cross-compile shader customizations are, as far as I know. I'd thought the other approach was the key to solving the issue, but it wasn't, so with things seeming to work now I feel better going with this instead. Hopefully that doesn't come back to bite us.

philstopford commented 5 years ago

Looks to be working fine here as well. Great work - thank you!

ItEndsWithTens commented 5 years ago

You're welcome! Man, is that a relief. It would be just my luck if it worked on my machine but nowhere else.

philstopford commented 5 years ago

Probably worth updating the readme based on this success