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] Add GGUI set_image support for non-Vector fields and numpy ndarrays. #5654

Merged
merged 10 commits into from
Aug 13, 2022

Conversation

Hyiker
Copy link
Contributor

@Hyiker Hyiker commented Aug 6, 2022

Related issue = close #5633

Fixing the issue and adding additional support for flat fields like (400, 400, 3). Also, I implemented support for numpy.ndarray following the document.

fixing copy range typo in copy_image_u8_to_rgba8;
adding numpy ndarray src support
@netlify
Copy link

netlify bot commented Aug 6, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 65e96db
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/62f77e18961e850009b07605
😎 Deploy Preview https://deploy-preview-5654--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@taichi-gardener taichi-gardener added this to In progress in GGUI Aug 6, 2022
Copy link
Member

@Morcki Morcki left a comment

Choose a reason for hiding this comment

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

Really good job! Thanks a lot for your contribution, I still have some doubts here if we can improve it.

@Morcki
Copy link
Member

Morcki commented Aug 12, 2022

Sorry, there have been some confilcts with others whose commitment include adding support for image texture type, I fix some confilcts, may you help to check it?
Very sorry to you for I do not merge into master in time cause there have been some bugs on the github CI workflow which took some time for our team to fix on this week. Thanks a lot again for your contributions! Wish you best!

@Hyiker
Copy link
Contributor Author

Hyiker commented Aug 13, 2022

Sorry, there have been some confilcts with others whose commitment include adding support for image texture type, I fix some confilcts, may you help to check it? Very sorry to you for I do not merge into master in time cause there have been some bugs on the github CI workflow which took some time for our team to fix on this week. Thanks a lot again for your contributions! Wish you best!

Sure, I rewrite some lines to improve the readability. Additionally, I created a test for flat fields in test_ggui.py, but when I'm trying to create one for numpy field, the test failed with:

E           RuntimeError: [D:/a/taichi/taichi/taichi/codegen/spirv/spirv_ir_builder.cpp:register_value@1185] tmp1 is existed.

However, in case I actually use a numpy ndarray as input, it just worked fine, I'm really confused. My numpy test code was like:

@pytest.mark.skipif(not _ti_core.GGUI_AVAILABLE, reason="GGUI Not Available")
@test_utils.test(arch=supported_archs)
def test_set_image_flat_field():
    window = ti.ui.Window('test', (640, 480), show_window=False)
    canvas = window.get_canvas()

    img = ti.field(ti.f32, (512, 512, 4))

    @ti.kernel
    def init_img():
        for i, j in ti.ndrange(img.shape[0], img.shape[1]):
            img[i, j, 0] = i / 512
            img[i, j, 1] = j / 512
            img[i, j, 2] = 0
            img[i, j, 3] = 1.0

    init_img()

    def render():
        canvas.set_image(img.to_numpy())

    for _ in range(RENDER_REPEAT):
        render()
        write_temp_image(window)
    render()
    verify_image(window, 'test_set_image')
    window.destroy()

I'm not quite familiar with taichi kernel code, wondering if u could help me solve it.

@Morcki
Copy link
Member

Morcki commented Aug 13, 2022

The problem is due to this line for i, j in ti.ndrange(src.shape[0], src.shape[1]):, you can replace it using ti.grouped() to solve this problem.
It seems like using ti.ndrange() for ti.ndarray() is not supported under vulkan backend, I think this is a bug. You can issue this for us.

Here is a simple test:

import taichi as ti

ti.init(arch=ti.vulkan)

@ti.kernel
def test_loop_under_vulkan(test_arr : ti.types.ndarray()):
    for i, j in ti.ndrange(test_arr.shape[0], test_arr.shape[1]):
        pass

ti_arr = ti.ndarray(ti.f32, (3,3,3))
test_loop_under_vulkan(ti_arr)

python/taichi/ui/staging_buffer.py Outdated Show resolved Hide resolved
python/taichi/ui/staging_buffer.py Outdated Show resolved Hide resolved
python/taichi/ui/staging_buffer.py Outdated Show resolved Hide resolved
@Hyiker Hyiker requested a review from Morcki August 13, 2022 10:33
@Hyiker
Copy link
Contributor Author

Hyiker commented Aug 13, 2022

Thx for reviewing, I've applied all your suggestion.
But the numpy test problem stills exists even if I used ti.grouped, I think it might be another bug and may open an individual issue for it.

@Morcki
Copy link
Member

Morcki commented Aug 13, 2022

So that's strange, cause I success with ti.grouped on my dev environment(Ubuntu 18).
Yeah, it seems like an individual issue which should be talked about in another issue.

@Morcki Morcki merged commit 67f1fe2 into taichi-dev:master Aug 13, 2022
GGUI automation moved this from In progress to Done Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
GGUI
Done
Development

Successfully merging this pull request may close these issues.

GGUI 1-component grayscale field support
2 participants