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
SurfacePlotVisual.set_data cause vertex shader to perform unnecessary build #2568
Comments
I agree. I think you're correct. I think this visual has not been optimized for this color logic which is surprising. I think @brisvag or maybe @tlambert03 did some work on the ImageVisual ( Lines 678 to 682 in b72a201
I think the original intention of the code or the idea behind it was that if you change the data then the colors array will also change (I'm not sure this is always necessary either). Since First, it would need to be updated so the function objects only get created once. I don't think there is a reason this shouldn't work. Next, it should be updated so if we already have a color transform but we are updating only the color limits, then just update the color limits. I think mocking this after the ImageVisual wouldn't be a terrible idea. This would mean something like a Lines 419 to 429 in b72a201
|
Yup, agree with the above! I don't have the bandwidth now to do with this, but if anyone wants to open a PR with this I'd be happy to review. |
@djhoese Thank you for your answer. In meshvisual, it is indeed necessary to use optimization logic similar to that already present in ImageVisual to avoid the repeated creation of function object。If I have time, I would be happy to try and contribute to the code. |
when I try to use scene.visuals.SurfacePlot.set_data with an app.Timer to get some animation effects,then I found that the CPU usage was very high.My core code like :
Then I traced the call process of the function from the source code,I found when the Superclass of SurfacePlotVisual,MeshVisual,calls the following code cause the vertex shader rebuild:
self.shared_program.vert['color_transform'] = self._build_color_transform(colors)
the line of mesh.py source code here:mesh.py
fun = Function(null_color_transform)
(build_color_transform) in the function_build_color_transform
create new Function object,when it call__setitem__
in the class Function function.py,the self.changed check process think both code_changed and value_changed,In the subsequent process, shared_program (shader) will be affected by thecode_changed
and believed that it need build(program.py),though the code for vertex shaders has not actually changed(the default text of null_color_transform:null_color_transform ).So,it seems like once I use the SurfacePlotVisual.set_data, it cause vertex shader build.But I just hope to use
set_data
to replace the visual data during the loop process, but I cannot avoid rebuilding the shader.Could someone help me or had a similar experience?The text was updated successfully, but these errors were encountered: