taichi
taichi copied to clipboard
[gui] Add GGUI set_image support for non-Vector fields and numpy ndarrays.
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.
Deploy Preview for docsite-preview ready!
Name | Link |
---|---|
Latest commit | 65e96dbf515145098b205d17f63c6598b5f343ac |
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
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!
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.
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)
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.
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
.