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

[GUI] [linux] Support "ti.GUI(fast_gui=True)" for zero-copy while gui.set_image(img) #1922

Merged
merged 6 commits into from
Oct 12, 2020

Conversation

archibate
Copy link
Collaborator

Related issue = depends #1921

[Click here for the format server]


We can now obtain 60fps even with 1920x1080!
This would allow me to implement a real-time soft renderer in Taichi THREE!

@Iteravse
Copy link

Iteravse commented Oct 5, 2020

tremendous progress!!!
it solved the question i was gonna ask
waiting for windows version 👍

@archibate archibate self-assigned this Oct 5, 2020
@archibate archibate marked this pull request as ready for review October 8, 2020 06:10
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do a merge master first? That should shrink the size of the PR

u, v, w = min(255, max(0, int(img[i, img.shape[1] - 1 - j] * 255)))
# We use i32 for |out| since OpenGL and Metal doesn't support u8 types
# TODO: treat Cocoa and Big-endian machines, with XOR logic
out[j * 1920 + i] = w + (v << 8) + (u << 16)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img.shape[1]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img.shape[0] actually.
Btw, I saw you use RGB order in cocoa.cpp, and BGR order in x11.cpp and win32.cpp. I want to know if mac actually use big-endian? If so, no changes need to be done here. Otherwise ti.static(ti.get_os_name() == 'osx') would be used.

@@ -21,6 +21,16 @@ def cook_image_type(x):
return x


@ti.kernel
def vector_to_fast_image(img: ti.template(), out: ti.ext_arr()):
# FIXME: Why is ``for i, j in img:`` slower than:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how much it was slower?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you reproduce it? I'm building right now. Will tell you asap. This is likely an issue of row-major / col-major, wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. I was just curious if the slowness was just some noise or not. It does sound like row-major vs column-major could be a factor. Thanks for confirming!

Did you reproduce it?

I tried running the example, but all i got was a black screen.. (Tried both RGB and BGR). Given that the original image was of type ti.f32, maybe that could be the reason? (Or do i actually need to pass fast_buf somewhere for Cocoa?)

python/taichi/misc/gui.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 10, 2020

Codecov Report

Merging #1922 into master will increase coverage by 0.85%.
The diff coverage is 23.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1922      +/-   ##
==========================================
+ Coverage   42.80%   43.65%   +0.85%     
==========================================
  Files          45       45              
  Lines        6413     6226     -187     
  Branches     1101     1107       +6     
==========================================
- Hits         2745     2718      -27     
+ Misses       3498     3334     -164     
- Partials      170      174       +4     
Impacted Files Coverage Δ
python/taichi/misc/gui.py 8.89% <19.04%> (ø)
python/taichi/lang/meta.py 62.82% <40.00%> (ø)
...ld/taichi-dev/taichi/python/taichi/tools/np2ply.py
...build/taichi-dev/taichi/python/taichi/lang/util.py
...uild/taichi-dev/taichi/python/taichi/tools/file.py
...build/taichi-dev/taichi/python/taichi/lang/meta.py
.../build/taichi-dev/taichi/python/taichi/torch_io.py
...build/taichi-dev/taichi/python/taichi/lang/core.py
...ild/taichi-dev/taichi/python/taichi/lang/kernel.py
...uild/taichi-dev/taichi/python/taichi/cc_compose.py
... and 82 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fa0d60...0955b07. Read the comment docs.

@archibate archibate requested a review from k-ye October 10, 2020 13:11
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM + nits!

python/taichi/misc/gui.py Outdated Show resolved Hide resolved
@@ -21,6 +21,16 @@ def cook_image_type(x):
return x


@ti.kernel
def vector_to_fast_image(img: ti.template(), out: ti.ext_arr()):
# FIXME: Why is ``for i, j in img:`` slower than:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. I was just curious if the slowness was just some noise or not. It does sound like row-major vs column-major could be a factor. Thanks for confirming!

Did you reproduce it?

I tried running the example, but all i got was a black screen.. (Tried both RGB and BGR). Given that the original image was of type ti.f32, maybe that could be the reason? (Or do i actually need to pass fast_buf somewhere for Cocoa?)

docs/gui.rst Outdated Show resolved Hide resolved
taichi/gui/gui.h Outdated Show resolved Hide resolved
@archibate
Copy link
Collaborator Author

Or do i actually need to pass fast_buf somewhere for Cocoa?

Yes, you need. This PR is only for x11.

taichi/python/export_visual.cpp Outdated Show resolved Hide resolved
taichi/gui/gui.h Outdated Show resolved Hide resolved
taichi/gui/gui.h Outdated Show resolved Hide resolved
taichi/gui/gui.h Outdated Show resolved Hide resolved
python/taichi/misc/gui.py Outdated Show resolved Hide resolved
Co-authored-by: Ye Kuang <k-ye@users.noreply.github.com>
@archibate
Copy link
Collaborator Author

Merging! FF2 do the Cocoa and Win32 part iapr :)

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

Successfully merging this pull request may close these issues.

4 participants