GPU Intersection

Did you run into this issue at all?, basically you can't erase/select or anything that requires intersection?
114 Replies
mikesky
mikeskyβ€’3y ago
We haven't touched that file at all during the upgrade and it seems to be working fine, the only thing we've encountered an issue with is a brief test with Oculus Passthrough, where the issue you describe appears. Nope, it's broken, see below I feel I'm going to have to look at that sooner rather than later though, so time to understand what the heck is going on in that class πŸ˜… Would love to hear about it if you manage to solve it (and how you did it!) @javierdavalos just in case this didn't ping you
andybak
andybakβ€’3y ago
@mikesky this happened when I did a build on my branch without passthrough (but with your xr stuff) haven't tried recently though
mikesky
mikeskyβ€’3y ago
I think that was broken for a different issue, but I'll set a build going while I grab lunch and check πŸ˜„
JavierD
JavierDOPβ€’3y ago
Hi guys, thanks for your replies. I'd love to contribute to solve this puzzle... Here is what I know so far: * Everything works perfectly fine in Unity 2019, Hololens 2, Quest passthrough, Qualcomm snapdragon AR glasses. * As soon as the project is updated to 2020.3, both Quest and Qualcomm break. both android devices, both using linear color space, Hololens 2 works great still and uses gamma. * Issue occurs ONLY on device, everything works great in the Unity editor I'm going to make a Linear color build for HL2 to see if that's the cause.
andybak
andybakβ€’3y ago
hmmmm. if it's linear/gamma - i'd expect it to break in the editor as well
mikesky
mikeskyβ€’3y ago
Okay looks like we might be having the same battle, I've just sanity checked as far back as our CI would let me, and it's not working there πŸ˜… I'm ripping my hair out because I was sure this was working at some point, enough for me to notice it supposedly 'broke' when trying passthrough
JavierD
JavierDOPβ€’3y ago
It's messed up because manufacturers are leaving Unity 2019 behind so we are being forced to upgrade.
mikesky
mikeskyβ€’3y ago
I think we've had it on both linear and gamma, therefore So we could probably rule that out
JavierD
JavierDOPβ€’3y ago
So you ran it on 2021 and it failed there too?
mikesky
mikeskyβ€’3y ago
Too right, That's why #archived-unity-xr has had to happen πŸ˜… Yes, 2020 and 2021 v38 through v40 as well so i'm gonna guess it's something unity side between 2019 -> 2020 (damn, I wish we'd put out a passthrough build on 2019 if you say that's working)
JavierD
JavierDOPβ€’3y ago
It is working, passthrough & linear Unity 2019
andybak
andybakβ€’3y ago
so - not specifically linear. and not oculus specific i hope it's not a unity 2020 bug 😦
JavierD
JavierDOPβ€’3y ago
I'l make a HL2 linear color build on 2020.3 and let you know if that works.
andybak
andybakβ€’3y ago
IntersectionDownsample.shader looks very sensitive to small differences in render behaviour
mikesky
mikeskyβ€’3y ago
Sooner it is then! I have zero knowledge with compute shaders This must also mean that Multibrush is still on 2019 πŸ€” Looks like this combined with not getting our pro key, means the beta is delayed another week then πŸ˜… sigh
andybak
andybakβ€’3y ago
This must also mean that Multibrush is still on 2019
unless they solved it The only compute shader used here is really trivial i don't think it's the cause. the two non-compute shaders look more suspicious
mikesky
mikeskyβ€’3y ago
I take it back, multibrush is running 2020.3
andybak
andybakβ€’3y ago
there's a define symbol "TILT_ENABLE_CONSERVATIVE_RASTER" - i wonder if it's worth trying setting that to true? oh. // TODO: This is currently disabled because of issues with back facing triangles.
mikesky
mikeskyβ€’3y ago
No description
andybak
andybakβ€’3y ago
NVIDIA Developer
Chapter 42. Conservative Rasterization
Chapter 42. Conservative Rasterization JonΒ Hasselgren LundΒ University TomasΒ Akenine-MΓΆller LundΒ University LennartΒ Ohlsson LundΒ University Over the past few years, general-purpose computation using GPUs has received much attention in the research community. The stream-based rasterization architecture provides for much faster performance growth t...
JavierD
JavierDOPβ€’3y ago
I tried that raster define, didn't help my notes from when I was trying to figure this out for Qualcomm glasses say that the intersection shader isn't returning anything (just black). I recall having a render texture to aid me in visualizing what is going on on device, I would make it show "curRenderSmall" on a texture. it all seemed black
andybak
andybakβ€’3y ago
Is it "all black whenever this is broken"? i.e. is that our canary?
mikesky
mikeskyβ€’3y ago
Interesting, android too right? I've been after a pair but qualcomm have been radio silent on any applications πŸ˜… HoloLens will be UWP though right, and that's broken too, hmm
JavierD
JavierDOPβ€’3y ago
yeah when you show that texture, normally you see some dim colors, they use that somehow to figure out what's being selected No, Hololens 2 works great. it is UWP.
andybak
andybakβ€’3y ago
is the common factor "broken on anything with a mobile chipset"? i.e. tiled renderer?
JavierD
JavierDOPβ€’3y ago
So either android is what is broken, or linear is broken
mikesky
mikeskyβ€’3y ago
Oh yeah I misread, my bad
JavierD
JavierDOPβ€’3y ago
HL2 linear color build is going to finish soon and we can rule that out
andybak
andybakβ€’3y ago
oh. i got confused about the hololens thing too. ignore me so - it's the intersection shader returning black? not "intersection and downsample" shader? we can rule out one of the two shaders.
JavierD
JavierDOPβ€’3y ago
I'm not sure really, i hastily looked at the problem and moved on. It was for a demo and I figure it was Qualcomm to blame, but now that it happens on Quest it's a big problem
mikesky
mikeskyβ€’3y ago
Yeah πŸ˜… I really wish i looked at this earlier
JavierD
JavierDOPβ€’3y ago
Ok we can rule out Linear color space as the culprit, a Hololens 2 build with linear on 2020.3 works fine
mikesky
mikeskyβ€’3y ago
Okay, good to know, thanks for testing that! hmm just gonna try another setting, doubt it'll work but worth a shot
andybak
andybakβ€’3y ago
the intersection camera initially renders to m_HighResTex - i'd be interested to know if that is all black
JavierD
JavierDOPβ€’3y ago
Try hooking up a material with a render texture so you can see it on device that's what I did
andybak
andybakβ€’3y ago
yeah. i was asking in a "hope somebody else tries this" kinda way πŸ˜‰
JavierD
JavierDOPβ€’3y ago
haha
andybak
andybakβ€’3y ago
i've got to pop out. i'm sure one of you will have magically fixed it by the time i get back!
mikesky
mikeskyβ€’3y ago
Will do as soon as i remember how to do this :^)
andybak
andybakβ€’3y ago
Makes me feel so much better so see it's not just me that completely forgets unity basics!
mikesky
mikeskyβ€’3y ago
Okay neither Vulkan or ES 3.2 helped
mikesky
mikeskyβ€’3y ago
tried all the settings here
No description
mikesky
mikeskyβ€’3y ago
Okay building with a debug plane Yep absolutely nothing from m_HighResTex @1_pld @captainxap Sorry for the ping, but any idea where this might be going wrong in Unity 2020+? πŸ˜…
Tim A
Tim Aβ€’3y ago
Sorry what is the problem?
andybak
andybakβ€’3y ago
Can you place some normal objects in the scene using that shader? That might tell us if it's the shader, or something to do with the intersection camera itself
mikesky
mikeskyβ€’3y ago
GPU intersection no longer works, so we can't select or erase, etc
Tim A
Tim Aβ€’3y ago
On Unity 2020?
mikesky
mikeskyβ€’3y ago
GitHub
open-brush/GpuIntersector.cs at main Β· icosa-gallery/open-brush
Open Brush is the FREE community led successor to Tilt Brush! - open-brush/GpuIntersector.cs at main Β· icosa-gallery/open-brush
mikesky
mikeskyβ€’3y ago
Yep, fine on 2019, but 2020 and 2021 just aren't working Like, make a material with it and put it on a cube?
andybak
andybakβ€’3y ago
Hmmmm. Might need vertex data from a real brush mesh Maybe change a brush definition so that it uses that shader and then just paint with it
mikesky
mikeskyβ€’3y ago
I'll try it tonight, gotta go now πŸ˜… hate leaving a problem hanging
Tim A
Tim Aβ€’3y ago
Probably worth trying to get a Renderdoc grab from device while it is selecting. IIRC it renders the selection to a small texture with its special shader
JavierD
JavierDOPβ€’3y ago
Ohh Hi Tim. Yeah we are having the same issue with Figmin XR after updating to Unity 2020. Worked perfectly fine in 2019
andybak
andybakβ€’3y ago
Wonder if it's worth posting on the Unity forums. Some teams are quite responsive.
JavierD
JavierDOPβ€’3y ago
While going through the ComputeShader docs I noticed they require RenderTextures to have enableRandomWrite = true. I made that change but unfortunately it didn't help. https://docs.unity3d.com/2020.3/Documentation/Manual/class-ComputeShader.html
mikesky
mikeskyβ€’3y ago
Just reopening as this got auto closed, set it to a week now. Haven’t had a chance to look at this again πŸ˜…
1pld
1pldβ€’3y ago
No idea about what might be going wrong with 2020. I could try reading the code again to try and help describe the general idea and architecture; but I think this is one of those things that will require some straight up investigation and debugging. Conservative rasterization is a red herring -- that's a minor quality improvement so that triangles smaller than 1 texel can still count as collisions. The render target for collisions is intentionally quite small, both to save on render time; and also to make the job easier for the compute shader which needs to calculate something like "are there any pixels set in this texture; if so, what is their color so I can map it back to a stroke id" Javier's suggestion above is basically the way I debugged this, previously: by looking at the intermediate textures in Unity. (Renderdoc would probably work too)
mikesky
mikeskyβ€’3y ago
Worked out how to get renderdoc set up for quest, but my debug builds aren't quite working for some reason πŸ˜… il2cpp is a pain sometimes... non-debug builds fine!
andybak
andybakβ€’3y ago
i'm wondering what the minimal repro for this is. if m_HighResTex is all black then that's nothing to do with the compute shader maybe a test scene with just some brush script generated geometry, the intersection camera and the "render with replacement shaders" line?
mikesky
mikeskyβ€’3y ago
I briefly considered making a test scene but GpuIntersector is quite entangled, would pretty much rewrite a new test class
andybak
andybakβ€’3y ago
but the code that renders to the texture is pretty simple. is there a way to repro this without a build? if a build wasn't required then i'd start with a totally minimal script and add stuff from the real scene bit by bit until it broke but that's painful with builds
mikesky
mikeskyβ€’3y ago
probably not 😦 though might be able to do some bisection in a similar way to reduce build count
andybak
andybakβ€’3y ago
Does that "instant preview" thing oculus introduced work? i never tried it i think it just does a quick minimal build each time
mikesky
mikeskyβ€’3y ago
the what now?
andybak
andybakβ€’3y ago
(or am i misremembering?)
mikesky
mikeskyβ€’3y ago
I didn't hear about that
andybak
andybakβ€’3y ago
you know - i might be thinking of google daydream πŸ˜‚
mikesky
mikeskyβ€’3y ago
a quick google says daydream lol, but did find this https://developer.oculus.com/documentation/unity/unity-build-android-tools/
Optimize Build Iterations for Android apps | Oculus Developers
Compile and build Android builds using OVR Build APK and Run and OVR Quick Scene Preview.
andybak
andybakβ€’3y ago
oooh! fixing bugs that only appear in a build might be my least favourite thing.
mikesky
mikeskyβ€’3y ago
No description
andybak
andybakβ€’3y ago
hmmm might not help us that much as our main scene is such a monolith
mikesky
mikeskyβ€’3y ago
maybe not but a minimal repro scene, maybe
andybak
andybakβ€’3y ago
true
mikesky
mikeskyβ€’3y ago
we can iterate fast in editor to set up the 'intended' view
andybak
andybakβ€’3y ago
you might get lucky. I have a hunch we'll repro the problem just with a camera and m_IntersectionCamera.RenderWithShader(m_IntersectionShader, string.Empty); be wary of a false negative if the brush geometry isn't actually created by a brush script test.color = PackUint16x2ToRgba8(uint2(_BatchID, id)); the mesh needs to have _BatchIDs oh no. that's not what Batchid is i wish i understood why the intersection camera renders a high res and then downsamples it using no filtering.
JavierD
JavierDOPβ€’3y ago
Man this is so frustrating, been banging my head with this for a while. I bet the fix is going to be something totally silly I also suspect m_IntersectionCamera.RenderWithShader is to blame
mikesky
mikeskyβ€’3y ago
Gonna throw 2 full days at this next week, been busy this week I think I understand this pretty well now. However, I can't for the life of me get oculus renderdoc into the main scene! Just get black. the build works fine if I run it without renderdoc It also says OpenGL isn't presenting anymore after a few seconds 😦
mikesky
mikeskyβ€’3y ago
i know for sure that the rendering camera is being moved to the right place, and is the right size
No description
JavierD
JavierDOPβ€’3y ago
Yup, I've never used renderdoc so can't help there. What I did next after what you are doing is to attach a little preview to the intersection manager that is showing the render texture used by the intersection (curRenderSmall) In the editor you'll see dim colors, on device it will be pitch black
mikesky
mikeskyβ€’3y ago
Yeah I had that too, but I just altered it to not use the intersection shader and look what we have!
No description
mikesky
mikeskyβ€’3y ago
So issue is most likely in the shader πŸ€”
JavierD
JavierDOPβ€’3y ago
Yeah that's my suspicion. Because if you don't do RenderWithShader and just do Render instead it will work
mikesky
mikeskyβ€’3y ago
using the high res texture but either works here yup yup
JavierD
JavierDOPβ€’3y ago
I was going to try and see if commenting out .filterMode = makes a difference. But I won't be able to today. My hunch is that something in the config is not compatible anymore in 2020+
mikesky
mikeskyβ€’3y ago
I'll have a play around now that i've got a good debug setup πŸ™‚ Thought I'd found a useful shortcut by getting the editor to run with -force-gles31aep but XR doesn't initialise 😦 That being said, might be easier to make a test scene and iterate in editor with this?
mikesky
mikeskyβ€’3y ago
https://github.com/icosa-gallery/open-brush/blob/feature/xr_v2/Assets/Shaders/Include/PackInt.cginc#L26 I also found this last night, interesting point! I wonder if this is now fixed in 2020 and up, and somehow broke the workaround πŸ˜…
GitHub
open-brush/PackInt.cginc at feature/xr_v2 Β· icosa-gallery/open-brush
Open Brush is the FREE community led successor to Tilt Brush! - open-brush/PackInt.cginc at feature/xr_v2 Β· icosa-gallery/open-brush
andybak
andybakβ€’3y ago
This smells like the right kind of place to look.
JavierD
JavierDOPβ€’3y ago
That is a good find @mikesky So you weren't able to load up renderdoc? https://developer.oculus.com/documentation/unity/ts-renderdoc-capture/ I was going to give it a go this weekend
mikesky
mikeskyβ€’3y ago
Yep that's the guide I followed, but after Open Brush's load screen it would crash but only with renderdoc connected 😦 perhaps Figmin will fare better! I'll need to give it a shot running logcat alongside to see what might be causing the crash
JavierD
JavierDOPβ€’3y ago
It did work i was able to make a capture but I haven't the faintest idea of what to look for I thought there woudl be some error logs but I can't see any
mikesky
mikeskyβ€’3y ago
Shaders are a bit of a black box like that πŸ˜… if you can take a capture of the moment you're supposedly selecting a stroke, you can save that capture file and I can take a look if you want?
JavierD
JavierDOPβ€’3y ago
sure I was able to find the intersection shader andwhen it's rendering I was able to see that the texture comes out black, just like we already knew but other than that I don't know what to look for.
mikesky
mikeskyβ€’3y ago
You can use the mesh view, so this is the output from the vertex shader
No description
mikesky
mikeskyβ€’3y ago
but the output from the geometry shader is blank
No description
mikesky
mikeskyβ€’3y ago
usually it would show you the bits of the mesh that were picked up for the selection So yep, something in the geometry shader isn't happy. Will try find some time to debug more but it's been a hectic week πŸ˜…
JavierD
JavierDOPβ€’3y ago
Ok well now at least we have some logs, and looks like you can actually read them :p
mikesky
mikeskyβ€’3y ago
Heh I used it briefly at uni, this is my first time in 4 years πŸ˜‚ If i'm interpreting it right (i may not be!) then it might not actually be the packInt bit that's the issue, as we're not even getting any geometry to assign color information to. it might be happening further up in the process would be good to test if hit is even occuring as if it doesn't it's completely discarded
mikesky
mikeskyβ€’3y ago
Will give this a shot πŸ˜„
No description
JavierD
JavierDOPβ€’3y ago
and what do you think about the first danger note, regarding float to unorm conversion. Could that be related? " // TODO: Danger! // https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf // Section 2.3.5.2 says that float -> unorm conversion isn't guaranteed to be // round-to-nearest. For full portability, we might need to sacrifice one bit per // channel with something like "(u1 >> 7) & 0x7f" and maybe add 0.5f. "
mikesky
mikeskyβ€’3y ago
oh hot damn, it works! it's the hit detection code somehow!! if you're alright with a box selector instead of a sphere, just remove that hit check and you'll (probably) be alright πŸ˜‰ damn I wasn't expecting that, should've tried this earlier
JavierD
JavierDOPβ€’3y ago
what hit check, i'm not following
mikesky
mikeskyβ€’3y ago
in intersection.shader, comment out the hit check in the geometry shader
No description
JavierD
JavierDOPβ€’3y ago
I'll make a build with that
mikesky
mikeskyβ€’3y ago
Okay, good luck! I'll be back later but ending the week happy even if I don't manage to get back to this πŸ˜„
JavierD
JavierDOPβ€’3y ago
Dude imma gonna love you if this works I was starting to considering rewritting that Heck yeah dude, it works once again! πŸ₯°
mikesky
mikeskyβ€’3y ago
Nice! πŸ˜„ glad to have helped, the purist in me will work out why that broke and fix it, it’s certainly an odd part to break. Note that your intersection is now a square instead of a sphere!
JavierD
JavierDOPβ€’3y ago
Yeah we'll definitely need to fix it, it's awkward right now. but at least it operates!
andybak
andybakβ€’3y ago
🧐 progress!
mikesky
mikeskyβ€’3y ago
Interestingly it seems to be the any function parts πŸ€”
bool hit = any(input[0].worldPos != input[1].worldPos)
&& any(input[0].worldPos != input[2].worldPos)
&& any(input[2].worldPos != input[1].worldPos)
bool hit = any(input[0].worldPos != input[1].worldPos)
&& any(input[0].worldPos != input[2].worldPos)
&& any(input[2].worldPos != input[1].worldPos)
mikeage
mikeageβ€’3y ago
Thanks for doing this one publicly rather than jn DMs. Can't say I followed everything, but it was interesting!
mikesky
mikeskyβ€’3y ago
Switching the logic to use all:
bool hit = !all(input[0].worldPos == input[1].worldPos)
&& !all(input[0].worldPos == input[2].worldPos)
&& !all(input[2].worldPos == input[1].worldPos)
bool hit = !all(input[0].worldPos == input[1].worldPos)
&& !all(input[0].worldPos == input[2].worldPos)
&& !all(input[2].worldPos == input[1].worldPos)
Still doesn't work 😦 works fine on PC, again I wonder how likely it is for this case to come up though. maybe we can get away with just removing the point comparison tests? Then we're just left with bool hit = SphereInTriangle(input[0].worldPos, input[1].worldPos, input[2].worldPos, vSphereCenter, fSphereRad); I'm gonna do the above ^ and move on for now, I'll comment out the point comparisons and try to figure it out later, it might just be a Unity bug πŸ˜… given that they broke the bitExtract function as mentioned in that other shader file, I wouldn't be surprised
JavierD
JavierDOPβ€’3y ago
I'm glad you were able to figure this one out! It was as tough as they get If you guys run into any issues and I'm able to help, hit me up, i'm up for collab
mikesky
mikeskyβ€’3y ago
Heh I'm glad too, though I think we got lucky, I'm still wrapping my head around this codebase πŸ˜… Glad to hear it, will definitely loop you in, and same if there's anything else we can help you with! πŸ™‚

Did you find this page helpful?