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

When sampling height using SampleHelpers or directly, the first request always fails #1013

Open
bfod opened this issue May 2, 2022 · 4 comments

Comments

@bfod
Copy link

bfod commented May 2, 2022

Describe the bug
We discovered this issue while trying to make an editor function to sample the water height. But it also affects play mode.

We start with your OceanSampleHeightDemo, which places a cube at the surface of the water. Out of the box this works fine. But if we try to run the Query just once, it always fails.

I put the function on a button instead and noticed that it would always work (either at edit or play time) if I double-clicked the button, and would never work if I clicked once (no error is thrown, it just fails to get a result)

We found line 121 of QueryBase.cs - it has an 'if age < 10'
basically here's what seems to be happening:

  • if I query twice or more and the queries are <10 frames apart, then it works and the results are returned almost instantly
  • if I query 1 time only, it never works even if we wait forever for the results to be filled
  • if I query more once, more than 10 frames apart, it doesn't work

We confirmed this behavior by increasing the age limit. It's not visible in normal gameplay where a query is being made at 30 or 60fps, but single queries will always fail.

I understand GPU queries are by nature async methods and we are happy to write async functions to handle the results. But even so, the first query should return results. We want to use it for our editor methods but also for one-time visual effects in gameplay, such as placing splash effects when an object first hits the water.

Log
Nothing in log

Versions
Built in renderer, latest Crest 2 May 2022, Unity 2021.3.0f1

To Reproduce
Open your sample scene. Create a cube and add OceanSampleHeightDemo. Modify the function to query water height just one time. You will see it never works.

Platform

  • Editor
  • Windows

Hardware
Geforce 2080 Super

@huwb
Copy link
Contributor

huwb commented May 2, 2022

Hello, the current system requires that one calls the query function each frame until it returns true and provides data. In other words it requires "polling" for the 2-3 frames until the result comes back.

I think we have an idea of how to make it behave more like what you are expecting but it would involve a major overhaul or replacement of the current system and I don't have a timeline on that currently. Can reply here again if that changes though.

@bfod
Copy link
Author

bfod commented May 2, 2022

That's fine, but I'd appreciate any advice you can give on the best way to work around this for an editor script. We can write an async method if required - performance is not an issue since this only will happen at build time. Should we just issue the request over and over again until it returns data? Will that work?

@huwb
Copy link
Contributor

huwb commented May 2, 2022

It's hard to say for sure but I suppose if you jump on the same tick that the OceanRenderer is using to drive its update (it also needs to update in edit mode/editor and so has its update code called from multiple places) it might all just work.

Generally it should also be safe to spam it at high frequency, I believe. Needs to be tried though.

@bfod
Copy link
Author

bfod commented May 2, 2022

Ok thanks we'll give it a try.

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

No branches or pull requests

3 participants