From 7809e82b802e6404f9995826a59437ec8345e6d1 Mon Sep 17 00:00:00 2001 From: Morcki Date: Fri, 29 Jul 2022 19:46:37 +0800 Subject: [PATCH 01/27] expose Polygon type and support for resetting graphics pipeline --- taichi/ui/backends/vulkan/renderable.cpp | 13 ++++++++++++- taichi/ui/backends/vulkan/renderable.h | 1 + taichi/ui/backends/vulkan/renderables/circles.cpp | 1 + taichi/ui/backends/vulkan/renderables/mesh.cpp | 1 + taichi/ui/backends/vulkan/renderables/particles.cpp | 1 + taichi/ui/common/app_config.h | 1 + taichi/ui/common/renderable_info.h | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/taichi/ui/backends/vulkan/renderable.cpp b/taichi/ui/backends/vulkan/renderable.cpp index 427e96032f187..bfca1bb66770a 100644 --- a/taichi/ui/backends/vulkan/renderable.cpp +++ b/taichi/ui/backends/vulkan/renderable.cpp @@ -48,6 +48,16 @@ void Renderable::update_data(const RenderableInfo &info) { prog->flush(); } + bool is_pipeline_reset = false; + + // Check if we need to update Graphics Pipeline + if (info.display_mode != config_.polygon_type) { + is_pipeline_reset = true; + config_.polygon_type = info.display_mode; + pipeline_.reset(); + create_graphics_pipeline(); + } + int num_vertices = info.vbo.shape[0]; int draw_num_vertices = info.draw_vertex_count; int draw_first_vertices = info.draw_first_vertex % num_vertices; @@ -88,7 +98,7 @@ void Renderable::update_data(const RenderableInfo &info) { config_.draw_first_index = 0; } - if (num_vertices > config_.max_vertices_count || + if (is_pipeline_reset || num_vertices > config_.max_vertices_count || num_indices > config_.max_indices_count) { free_buffers(); config_.max_vertices_count = num_vertices; @@ -165,6 +175,7 @@ void Renderable::create_graphics_pipeline() { RasterParams raster_params; raster_params.prim_topology = config_.topology_type; + raster_params.polygon_mode = config_.polygon_type; raster_params.depth_test = true; raster_params.depth_write = true; diff --git a/taichi/ui/backends/vulkan/renderable.h b/taichi/ui/backends/vulkan/renderable.h index 71d9ce1f59886..eeaaa7bdd65a9 100644 --- a/taichi/ui/backends/vulkan/renderable.h +++ b/taichi/ui/backends/vulkan/renderable.h @@ -40,6 +40,7 @@ struct RenderableConfig { std::string fragment_shader_path; taichi::lang::TopologyType topology_type{ taichi::lang::TopologyType::Triangles}; + taichi::lang::PolygonMode polygon_type{taichi::lang::PolygonMode::Fill}; VertexAttributes vbo_attrs{VboHelpers::all()}; size_t vbo_size() const { diff --git a/taichi/ui/backends/vulkan/renderables/circles.cpp b/taichi/ui/backends/vulkan/renderables/circles.cpp index 8083676d0393c..856c5bfb249cb 100644 --- a/taichi/ui/backends/vulkan/renderables/circles.cpp +++ b/taichi/ui/backends/vulkan/renderables/circles.cpp @@ -34,6 +34,7 @@ void Circles::init_circles(AppContext *app_context, app_context->config.package_path + "/shaders/Circles_vk_vert.spv", app_context->config.package_path + "/shaders/Circles_vk_frag.spv", TopologyType::Points, + PolygonMode::Fill, vbo_attrs, }; diff --git a/taichi/ui/backends/vulkan/renderables/mesh.cpp b/taichi/ui/backends/vulkan/renderables/mesh.cpp index 758f6041caf91..d431f2d5ab660 100644 --- a/taichi/ui/backends/vulkan/renderables/mesh.cpp +++ b/taichi/ui/backends/vulkan/renderables/mesh.cpp @@ -137,6 +137,7 @@ void Mesh::init_mesh(AppContext *app_context, app_context->config.package_path + "/shaders/Mesh_vk_vert.spv", app_context->config.package_path + "/shaders/Mesh_vk_frag.spv", TopologyType::Triangles, + PolygonMode::Fill, vbo_attrs, }; diff --git a/taichi/ui/backends/vulkan/renderables/particles.cpp b/taichi/ui/backends/vulkan/renderables/particles.cpp index c5f00ea2b5b36..836ad618a04b0 100644 --- a/taichi/ui/backends/vulkan/renderables/particles.cpp +++ b/taichi/ui/backends/vulkan/renderables/particles.cpp @@ -66,6 +66,7 @@ void Particles::init_particles(AppContext *app_context, app_context->config.package_path + "/shaders/Particles_vk_vert.spv", app_context->config.package_path + "/shaders/Particles_vk_frag.spv", TopologyType::Points, + PolygonMode::Fill, vbo_attrs, }; diff --git a/taichi/ui/common/app_config.h b/taichi/ui/common/app_config.h index 81a92800313c9..048cf1a950fd2 100644 --- a/taichi/ui/common/app_config.h +++ b/taichi/ui/common/app_config.h @@ -3,6 +3,7 @@ #include #include "taichi/ui/utils/utils.h" #include "taichi/rhi/arch.h" +#include "taichi/rhi/vulkan/vulkan_device.h" namespace taichi { namespace ui { diff --git a/taichi/ui/common/renderable_info.h b/taichi/ui/common/renderable_info.h index 4752000fd3cb9..68cd0aa2e36b4 100644 --- a/taichi/ui/common/renderable_info.h +++ b/taichi/ui/common/renderable_info.h @@ -16,6 +16,7 @@ struct RenderableInfo { int draw_first_vertex{0}; int draw_index_count{0}; int draw_first_index{0}; + taichi::lang::PolygonMode display_mode{taichi::lang::PolygonMode::Fill}; }; TI_UI_NAMESPACE_END From e91a782f102d80c95bef43d6ca375ade8bb7bb2d Mon Sep 17 00:00:00 2001 From: Morcki Date: Fri, 29 Jul 2022 19:47:50 +0800 Subject: [PATCH 02/27] Support 3 kinds of display mode(0:Fill,1:Line,2:Point) for Scene.mesh & Scene.mesh_instance --- python/taichi/ui/scene.py | 31 +++++++++++++++++++++++-------- taichi/python/export_ggui.cpp | 8 ++++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index f5685dd2b61ee..b34f039e51389 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -9,6 +9,7 @@ from .staging_buffer import (copy_colors_to_vbo, copy_normals_to_vbo, copy_vertices_to_vbo, get_vbo_field) from .utils import check_ggui_availability, get_field_info + normals_field_cache = {} @@ -170,7 +171,8 @@ def mesh(self, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, - index_count: int = None): + index_count: int = None, + display_mode : int = 0): """Declare a mesh inside the scene. if you indicate the index_offset and index_count, the normals will also @@ -205,6 +207,9 @@ def mesh(self, index_count (int, optional): only available when `indices` is provided, which is the the number of vertices to draw. + display_mode (int, optional): + there are 3 types of diplay mode, 0 equals Fill mode(Fill colors to all triagnles) + 1 equals Line mode(WareFrame), 2 equals Point mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -220,13 +225,16 @@ def mesh(self, index_count = vertex_count # FIXME : Need to confirm else: index_count = indices.shape[0] + if display_mode < 0 or display_mode >= 3: + print("Error! display_mode must be 0(Fill), 1(Line), 2(Point)") + exit() copy_normals_to_vbo(vbo, normals) vbo_info = get_field_info(vbo) indices_info = get_field_info(indices) self.scene.mesh(vbo_info, has_per_vertex_color, indices_info, color, two_sided, index_count, index_offset, vertex_count, - vertex_offset) + vertex_offset, display_mode) def mesh_instance(self, vertices, @@ -236,11 +244,12 @@ def mesh_instance(self, per_vertex_color=None, two_sided=False, transforms=None, - draw_first_instance: int = 0, + instance_offset: int = 0, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, - index_count: int = None): + index_count: int = None, + display_mode : int = 0): """Declare lots of mesh instances inside the scene. If transforms is given, then according to the shape of transforms, we will @@ -267,9 +276,9 @@ def mesh_instance(self, transforms (ti.Matrix.field, optional): The Matrix must be 4x4 size with N instances, and data type should be ti.f32, ti.i32, ti.u32. If None, then it behaves like raw mesh (no copy). - draw_first_instance (int, optional): + instance_offset (int, optional): Default value is 0 which means no offset to show mesh instances. Otherwise, - the mesh instances will show from the `draw_first_instance`. + the mesh instances will show from the `instance_offset`. vertex_offset (int, optional): if 'indices' is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the @@ -283,6 +292,9 @@ def mesh_instance(self, index_count (int, optional): only available when `indices` is provided, which is the the number of vertices to draw. + display_mode (int, optional): + there are 3 types of diplay mode, 0 equals Fill mode(Fill colors to all triagnles) + 1 equals Line mode(WareFrame), 2 equals Point mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -301,14 +313,17 @@ def mesh_instance(self, if transforms and (transforms.m != 4 or transforms.n != 4): print("Error! Transform matrix must be 4x4 shape") exit() + if display_mode < 0 or display_mode >= 3: + print("Error! display_mode must be 0(Fill), 1(Line), 2(Point)") + exit() copy_normals_to_vbo(vbo, normals) vbo_info = get_field_info(vbo) indices_info = get_field_info(indices) transform_info = get_field_info(transforms) self.scene.mesh_instance(vbo_info, has_per_vertex_color, indices_info, color, two_sided, transform_info, - draw_first_instance, index_count, - index_offset, vertex_count, vertex_offset) + instance_offset, index_count, + index_offset, vertex_count, vertex_offset, display_mode) def particles(self, centers, diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 17c02c452a4c0..a1c7acac31038 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -172,7 +172,8 @@ struct PyScene { float draw_index_count, float draw_first_index, float draw_vertex_count, - float draw_first_vertex) { + float draw_first_vertex, + int display_mode) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -182,6 +183,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; + renderable_info.display_mode = taichi::lang::PolygonMode(display_mode); MeshInfo info; info.renderable_info = renderable_info; @@ -222,7 +224,8 @@ struct PyScene { float draw_index_count, float draw_first_index, float draw_vertex_count, - float draw_first_vertex) { + float draw_first_vertex, + int display_mode) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -232,6 +235,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; + renderable_info.display_mode = taichi::lang::PolygonMode(display_mode); MeshInfo info; info.renderable_info = renderable_info; From 46d24b10c33b3021b45691b0365e16e3e2da1c2b Mon Sep 17 00:00:00 2001 From: Morcki Date: Fri, 29 Jul 2022 20:34:24 +0800 Subject: [PATCH 03/27] Set default background color --- taichi/ui/backends/vulkan/renderer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/ui/backends/vulkan/renderer.h b/taichi/ui/backends/vulkan/renderer.h index e7e0084e67346..0576b31fb4676 100644 --- a/taichi/ui/backends/vulkan/renderer.h +++ b/taichi/ui/backends/vulkan/renderer.h @@ -78,8 +78,8 @@ class TI_DLL_EXPORT Renderer { taichi::lang::StreamSemaphore get_render_complete_semaphore(); private: - glm::vec3 background_color_ = glm::vec3(0.f, 0.f, 0.f); - + glm::vec3 background_color_ = glm::vec3(0.45f, 0.55f, 0.60f); + std::vector> renderables_; int next_renderable_; From e12517e41b6b519e8f0096ad876a40cc3ba46705 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 29 Jul 2022 13:39:09 +0000 Subject: [PATCH 04/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/scene.py | 9 ++++----- taichi/ui/backends/vulkan/renderable.h | 2 +- taichi/ui/backends/vulkan/renderer.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index b34f039e51389..3b6e015d5e384 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -9,7 +9,6 @@ from .staging_buffer import (copy_colors_to_vbo, copy_normals_to_vbo, copy_vertices_to_vbo, get_vbo_field) from .utils import check_ggui_availability, get_field_info - normals_field_cache = {} @@ -172,7 +171,7 @@ def mesh(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode : int = 0): + display_mode: int = 0): """Declare a mesh inside the scene. if you indicate the index_offset and index_count, the normals will also @@ -249,7 +248,7 @@ def mesh_instance(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode : int = 0): + display_mode: int = 0): """Declare lots of mesh instances inside the scene. If transforms is given, then according to the shape of transforms, we will @@ -322,8 +321,8 @@ def mesh_instance(self, transform_info = get_field_info(transforms) self.scene.mesh_instance(vbo_info, has_per_vertex_color, indices_info, color, two_sided, transform_info, - instance_offset, index_count, - index_offset, vertex_count, vertex_offset, display_mode) + instance_offset, index_count, index_offset, + vertex_count, vertex_offset, display_mode) def particles(self, centers, diff --git a/taichi/ui/backends/vulkan/renderable.h b/taichi/ui/backends/vulkan/renderable.h index eeaaa7bdd65a9..2577fa9ce62ea 100644 --- a/taichi/ui/backends/vulkan/renderable.h +++ b/taichi/ui/backends/vulkan/renderable.h @@ -40,7 +40,7 @@ struct RenderableConfig { std::string fragment_shader_path; taichi::lang::TopologyType topology_type{ taichi::lang::TopologyType::Triangles}; - taichi::lang::PolygonMode polygon_type{taichi::lang::PolygonMode::Fill}; + taichi::lang::PolygonMode polygon_type{taichi::lang::PolygonMode::Fill}; VertexAttributes vbo_attrs{VboHelpers::all()}; size_t vbo_size() const { diff --git a/taichi/ui/backends/vulkan/renderer.h b/taichi/ui/backends/vulkan/renderer.h index 0576b31fb4676..4842be5847841 100644 --- a/taichi/ui/backends/vulkan/renderer.h +++ b/taichi/ui/backends/vulkan/renderer.h @@ -79,7 +79,7 @@ class TI_DLL_EXPORT Renderer { private: glm::vec3 background_color_ = glm::vec3(0.45f, 0.55f, 0.60f); - + std::vector> renderables_; int next_renderable_; From 9c7cfa32bbebfb49d737fb86313948c40ba28a5a Mon Sep 17 00:00:00 2001 From: Morcki Date: Sun, 31 Jul 2022 14:27:42 +0800 Subject: [PATCH 05/27] Add slider_int to support int type value --- python/taichi/ui/imgui.py | 14 ++++++++++++++ taichi/python/export_ggui.cpp | 4 ++++ taichi/ui/backends/vulkan/gui.cpp | 7 +++++++ taichi/ui/backends/vulkan/gui.h | 1 + taichi/ui/common/gui_base.h | 1 + 5 files changed, 27 insertions(+) diff --git a/python/taichi/ui/imgui.py b/python/taichi/ui/imgui.py index 38e284de2e304..644abde49fb74 100644 --- a/python/taichi/ui/imgui.py +++ b/python/taichi/ui/imgui.py @@ -71,6 +71,20 @@ def checkbox(self, text, old_value): old_value (bool): whether the checkbox is currently checked. """ return self.gui.checkbox(text, old_value) + + def slider_int(self, text, old_value, minimum, maximum): + """Declares a slider, and returns its newest value. + + Args: + text (str): a line of text to be shown next to the slider + old_value (int) : the current value of the slider. + minimum (int): the minimum value of the slider. + maximum (int): the maximum value of the slider. + + Returns: + int: the updated value of the slider. + """ + return self.gui.slider_int(text, old_value, minimum, maximum) def slider_float(self, text, old_value, minimum, maximum): """Declares a slider, and returns its newest value. diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index a1c7acac31038..7bc0c897f1c61 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -66,6 +66,9 @@ struct PyGui { bool checkbox(std::string name, bool old_value) { return gui->checkbox(name, old_value); } + int slider_int(std::string name, int old_value, int minimum, int maximum) { + return gui->slider_int(name, old_value, minimum, maximum); + } float slider_float(std::string name, float old_value, float minimum, @@ -498,6 +501,7 @@ void export_ggui(py::module &m) { .def("end", &PyGui::end) .def("text", &PyGui::text) .def("checkbox", &PyGui::checkbox) + .def("slider_int", &PyGui::slider_int) .def("slider_float", &PyGui::slider_float) .def("color_edit_3", &PyGui::color_edit_3) .def("button", &PyGui::button); diff --git a/taichi/ui/backends/vulkan/gui.cpp b/taichi/ui/backends/vulkan/gui.cpp index d169110b77f9b..80974103f3949 100644 --- a/taichi/ui/backends/vulkan/gui.cpp +++ b/taichi/ui/backends/vulkan/gui.cpp @@ -159,6 +159,13 @@ bool Gui::checkbox(std::string name, bool old_value) { ImGui::Checkbox(name.c_str(), &old_value); return old_value; } +int Gui::slider_int(std::string name, int old_value, int minimum, int maximum) { + if (!initialized()) { + return old_value; + } + ImGui::SliderInt(name.c_str(), &old_value, minimum, maximum); + return old_value; +} float Gui::slider_float(std::string name, float old_value, float minimum, diff --git a/taichi/ui/backends/vulkan/gui.h b/taichi/ui/backends/vulkan/gui.h index 41ebb6a906a25..91363db0ed150 100644 --- a/taichi/ui/backends/vulkan/gui.h +++ b/taichi/ui/backends/vulkan/gui.h @@ -38,6 +38,7 @@ class TI_DLL_EXPORT Gui final : public GuiBase { virtual void end() override; virtual void text(std::string text) override; virtual bool checkbox(std::string name, bool old_value) override; + virtual int slider_int(std::string name, int old_value, int minimum, int maximum) override; virtual float slider_float(std::string name, float old_value, float minimum, diff --git a/taichi/ui/common/gui_base.h b/taichi/ui/common/gui_base.h index 6aae3d11aba63..6e2f30b6c3f21 100644 --- a/taichi/ui/common/gui_base.h +++ b/taichi/ui/common/gui_base.h @@ -14,6 +14,7 @@ class GuiBase { virtual void end() = 0; virtual void text(std::string text) = 0; virtual bool checkbox(std::string name, bool old_value) = 0; + virtual int slider_int(std::string name, int old_value, int minimum, int maximum) = 0; virtual float slider_float(std::string name, float old_value, float minimum, From 9a74720780d72ecf91c4eca9e8e49e9b91ff9c62 Mon Sep 17 00:00:00 2001 From: Morcki Date: Sun, 31 Jul 2022 14:29:02 +0800 Subject: [PATCH 06/27] remove background color cause it would affect the some tests of verifying ground-truth images --- taichi/ui/backends/vulkan/renderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/ui/backends/vulkan/renderer.h b/taichi/ui/backends/vulkan/renderer.h index 4842be5847841..d8ecfa8455772 100644 --- a/taichi/ui/backends/vulkan/renderer.h +++ b/taichi/ui/backends/vulkan/renderer.h @@ -78,7 +78,7 @@ class TI_DLL_EXPORT Renderer { taichi::lang::StreamSemaphore get_render_complete_semaphore(); private: - glm::vec3 background_color_ = glm::vec3(0.45f, 0.55f, 0.60f); + glm::vec3 background_color_ = glm::vec3(0.f, 0.f, 0.0f); std::vector> renderables_; int next_renderable_; From 01f8ac3a7d955b79a86d6d672fe3362136aed875 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 Jul 2022 06:30:30 +0000 Subject: [PATCH 07/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/imgui.py | 2 +- taichi/ui/backends/vulkan/gui.h | 5 ++++- taichi/ui/common/gui_base.h | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/taichi/ui/imgui.py b/python/taichi/ui/imgui.py index 644abde49fb74..0c67cf0d067c1 100644 --- a/python/taichi/ui/imgui.py +++ b/python/taichi/ui/imgui.py @@ -71,7 +71,7 @@ def checkbox(self, text, old_value): old_value (bool): whether the checkbox is currently checked. """ return self.gui.checkbox(text, old_value) - + def slider_int(self, text, old_value, minimum, maximum): """Declares a slider, and returns its newest value. diff --git a/taichi/ui/backends/vulkan/gui.h b/taichi/ui/backends/vulkan/gui.h index 91363db0ed150..ac0328258e843 100644 --- a/taichi/ui/backends/vulkan/gui.h +++ b/taichi/ui/backends/vulkan/gui.h @@ -38,7 +38,10 @@ class TI_DLL_EXPORT Gui final : public GuiBase { virtual void end() override; virtual void text(std::string text) override; virtual bool checkbox(std::string name, bool old_value) override; - virtual int slider_int(std::string name, int old_value, int minimum, int maximum) override; + virtual int slider_int(std::string name, + int old_value, + int minimum, + int maximum) override; virtual float slider_float(std::string name, float old_value, float minimum, diff --git a/taichi/ui/common/gui_base.h b/taichi/ui/common/gui_base.h index 6e2f30b6c3f21..756f790b122cc 100644 --- a/taichi/ui/common/gui_base.h +++ b/taichi/ui/common/gui_base.h @@ -14,7 +14,10 @@ class GuiBase { virtual void end() = 0; virtual void text(std::string text) = 0; virtual bool checkbox(std::string name, bool old_value) = 0; - virtual int slider_int(std::string name, int old_value, int minimum, int maximum) = 0; + virtual int slider_int(std::string name, + int old_value, + int minimum, + int maximum) = 0; virtual float slider_float(std::string name, float old_value, float minimum, From a37bd6b59fc12a782553db2560dbbc022090e86b Mon Sep 17 00:00:00 2001 From: Morcki Date: Mon, 1 Aug 2022 14:34:07 +0800 Subject: [PATCH 08/27] expose enum class of PolygonMode to python scope naming as DisplayMode --- python/taichi/ui/scene.py | 41 +++++++++++++++++++++-------------- python/taichi/ui/ui.py | 2 +- taichi/python/export_ggui.cpp | 14 ++++++++---- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index 3b6e015d5e384..24ea849221ec4 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -12,6 +12,22 @@ normals_field_cache = {} +class DisplayMode_: + Fill = _ti_core.DisplayMode.Fill + Line = _ti_core.DisplayMode.Line + Point = _ti_core.DisplayMode.Point + @staticmethod + def __call__(mode : int): + if mode == 0: + return DisplayMode_.Fill + elif mode == 1: + return DisplayMode_.Line + elif mode == 2: + return DisplayMode_.Point + else: + raise Exception("Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)") + +DisplayMode = DisplayMode_() def get_normals_field(vertices): if vertices not in normals_field_cache: @@ -171,7 +187,7 @@ def mesh(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode: int = 0): + display_mode = DisplayMode.Fill): """Declare a mesh inside the scene. if you indicate the index_offset and index_count, the normals will also @@ -206,9 +222,9 @@ def mesh(self, index_count (int, optional): only available when `indices` is provided, which is the the number of vertices to draw. - display_mode (int, optional): - there are 3 types of diplay mode, 0 equals Fill mode(Fill colors to all triagnles) - 1 equals Line mode(WareFrame), 2 equals Point mode. + display_mode (Enum of DisplayMode, optional): + there are 3 types of diplay mode, Fill mode(Fill colors to all triagnles) + Line mode(WareFrame), Point mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -224,9 +240,6 @@ def mesh(self, index_count = vertex_count # FIXME : Need to confirm else: index_count = indices.shape[0] - if display_mode < 0 or display_mode >= 3: - print("Error! display_mode must be 0(Fill), 1(Line), 2(Point)") - exit() copy_normals_to_vbo(vbo, normals) vbo_info = get_field_info(vbo) indices_info = get_field_info(indices) @@ -248,7 +261,7 @@ def mesh_instance(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode: int = 0): + display_mode = DisplayMode.Fill): """Declare lots of mesh instances inside the scene. If transforms is given, then according to the shape of transforms, we will @@ -291,9 +304,9 @@ def mesh_instance(self, index_count (int, optional): only available when `indices` is provided, which is the the number of vertices to draw. - display_mode (int, optional): - there are 3 types of diplay mode, 0 equals Fill mode(Fill colors to all triagnles) - 1 equals Line mode(WareFrame), 2 equals Point mode. + display_mode (Enum of DisplayMode, optional): + there are 3 types of diplay mode, Fill mode(Fill colors to all triagnles) + Line mode(WareFrame), Point mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -310,11 +323,7 @@ def mesh_instance(self, else: index_count = indices.shape[0] if transforms and (transforms.m != 4 or transforms.n != 4): - print("Error! Transform matrix must be 4x4 shape") - exit() - if display_mode < 0 or display_mode >= 3: - print("Error! display_mode must be 0(Fill), 1(Line), 2(Point)") - exit() + raise Exception("Error! Transform matrix must be 4x4 shape") copy_normals_to_vbo(vbo, normals) vbo_info = get_field_info(vbo) indices_info = get_field_info(indices) diff --git a/python/taichi/ui/ui.py b/python/taichi/ui/ui.py index fea324e19070b..f81b1b05bc8c3 100644 --- a/python/taichi/ui/ui.py +++ b/python/taichi/ui/ui.py @@ -4,7 +4,7 @@ from .canvas import Canvas # pylint: disable=unused-import from .constants import * # pylint: disable=unused-import,wildcard-import from .imgui import Gui # pylint: disable=unused-import -from .scene import Scene # pylint: disable=unused-import +from .scene import Scene, DisplayMode # pylint: disable=unused-import from .utils import check_ggui_availability from .window import Window # pylint: disable=unused-import diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 7bc0c897f1c61..0dab3f8a6a89c 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -176,7 +176,7 @@ struct PyScene { float draw_first_index, float draw_vertex_count, float draw_first_vertex, - int display_mode) { + taichi::lang::PolygonMode display_mode) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -186,7 +186,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = taichi::lang::PolygonMode(display_mode); + renderable_info.display_mode = display_mode; MeshInfo info; info.renderable_info = renderable_info; @@ -228,7 +228,7 @@ struct PyScene { float draw_first_index, float draw_vertex_count, float draw_first_vertex, - int display_mode) { + taichi::lang::PolygonMode display_mode) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -238,7 +238,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = taichi::lang::PolygonMode(display_mode); + renderable_info.display_mode = display_mode; MeshInfo info; info.renderable_info = renderable_info; @@ -571,6 +571,12 @@ void export_ggui(py::module &m) { .value("Perspective", ProjectionMode::Perspective) .value("Orthogonal", ProjectionMode::Orthogonal) .export_values(); + + py::enum_(m, "DisplayMode", py::arithmetic()) + .value("Fill", taichi::lang::PolygonMode::Fill) + .value("Line", taichi::lang::PolygonMode::Line) + .value("Point", taichi::lang::PolygonMode::Point) + .export_values(); } TI_UI_NAMESPACE_END From 6ee70bbd99f1df74d0df78d51a886dcf3827ffd0 Mon Sep 17 00:00:00 2001 From: Morcki Date: Mon, 1 Aug 2022 14:34:34 +0800 Subject: [PATCH 09/27] change print-exit to raise exception --- python/taichi/ui/window.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python/taichi/ui/window.py b/python/taichi/ui/window.py index 3ebac72556c42..b2fb8bfafd5fc 100644 --- a/python/taichi/ui/window.py +++ b/python/taichi/ui/window.py @@ -146,11 +146,9 @@ def get_depth_buffer(self, depth): depth(ti.ndarray/ti.field): [window_width, window_height] carries depth information. """ if not (len(depth.shape) == 2 and depth.dtype == f32): - print("Only Support 2d-shape and ti.f32 data format.") - exit() + raise Exception("Only Support 2d-shape and ti.f32 data format.") if not isinstance(depth, (Ndarray, Field)): - print("Only Support Ndarray and Field data type.") - exit() + raise Exception("Only Support Ndarray and Field data type.") tmp_depth = get_depth_ndarray(self.window) self.window.copy_depth_buffer_to_ndarray(tmp_depth.arr) if isinstance(depth, Ndarray): From 74f7ac16d35c7810eb4d604a5fd7edaa16734eba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 06:36:04 +0000 Subject: [PATCH 10/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/scene.py | 14 ++++++++++---- python/taichi/ui/ui.py | 2 +- taichi/python/export_ggui.cpp | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index 24ea849221ec4..a14450aaf262a 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -12,12 +12,14 @@ normals_field_cache = {} + class DisplayMode_: Fill = _ti_core.DisplayMode.Fill Line = _ti_core.DisplayMode.Line Point = _ti_core.DisplayMode.Point + @staticmethod - def __call__(mode : int): + def __call__(mode: int): if mode == 0: return DisplayMode_.Fill elif mode == 1: @@ -25,10 +27,14 @@ def __call__(mode : int): elif mode == 2: return DisplayMode_.Point else: - raise Exception("Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)") + raise Exception( + "Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)" + ) + DisplayMode = DisplayMode_() + def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] @@ -187,7 +193,7 @@ def mesh(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode = DisplayMode.Fill): + display_mode=DisplayMode.Fill): """Declare a mesh inside the scene. if you indicate the index_offset and index_count, the normals will also @@ -261,7 +267,7 @@ def mesh_instance(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode = DisplayMode.Fill): + display_mode=DisplayMode.Fill): """Declare lots of mesh instances inside the scene. If transforms is given, then according to the shape of transforms, we will diff --git a/python/taichi/ui/ui.py b/python/taichi/ui/ui.py index f81b1b05bc8c3..daa98bc6328cf 100644 --- a/python/taichi/ui/ui.py +++ b/python/taichi/ui/ui.py @@ -4,7 +4,7 @@ from .canvas import Canvas # pylint: disable=unused-import from .constants import * # pylint: disable=unused-import,wildcard-import from .imgui import Gui # pylint: disable=unused-import -from .scene import Scene, DisplayMode # pylint: disable=unused-import +from .scene import DisplayMode, Scene # pylint: disable=unused-import from .utils import check_ggui_availability from .window import Window # pylint: disable=unused-import diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 0dab3f8a6a89c..9578523b0e34d 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -571,7 +571,7 @@ void export_ggui(py::module &m) { .value("Perspective", ProjectionMode::Perspective) .value("Orthogonal", ProjectionMode::Orthogonal) .export_values(); - + py::enum_(m, "DisplayMode", py::arithmetic()) .value("Fill", taichi::lang::PolygonMode::Fill) .value("Line", taichi::lang::PolygonMode::Line) From b9c4fb2f71bcf9d8f4d1ebc1b51fd5f241e0b154 Mon Sep 17 00:00:00 2001 From: Morcki Date: Mon, 1 Aug 2022 14:54:09 +0800 Subject: [PATCH 11/27] fix python format --- python/taichi/ui/scene.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index a14450aaf262a..d10a43be65457 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -22,19 +22,14 @@ class DisplayMode_: def __call__(mode: int): if mode == 0: return DisplayMode_.Fill - elif mode == 1: + if mode == 1: return DisplayMode_.Line - elif mode == 2: + if mode == 2: return DisplayMode_.Point - else: - raise Exception( - "Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)" - ) - + raise Exception("Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)") DisplayMode = DisplayMode_() - def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] From f0d36c9c8291ce21dc82bd56eaaca92efcc29c59 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 06:55:37 +0000 Subject: [PATCH 12/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/scene.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index d10a43be65457..9bee1621f6121 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -26,10 +26,14 @@ def __call__(mode: int): return DisplayMode_.Line if mode == 2: return DisplayMode_.Point - raise Exception("Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)") + raise Exception( + "Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)" + ) + DisplayMode = DisplayMode_() + def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] From 498f1bc6c6b10b8c8a7bb373c6cf695240904b0a Mon Sep 17 00:00:00 2001 From: Morcki Date: Mon, 1 Aug 2022 15:35:02 +0800 Subject: [PATCH 13/27] fix when not support GGUI --- python/taichi/ui/scene.py | 6 +++--- taichi/python/export_ggui.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index 9bee1621f6121..e144e0010b291 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -14,9 +14,9 @@ class DisplayMode_: - Fill = _ti_core.DisplayMode.Fill - Line = _ti_core.DisplayMode.Line - Point = _ti_core.DisplayMode.Point + Fill = _ti_core.DisplayMode.Fill if _ti_core.GGUI_AVAILABLE else None + Line = _ti_core.DisplayMode.Line if _ti_core.GGUI_AVAILABLE else None + Point = _ti_core.DisplayMode.Point if _ti_core.GGUI_AVAILABLE else None @staticmethod def __call__(mode: int): diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 9578523b0e34d..a2c49922fef4a 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -572,7 +572,7 @@ void export_ggui(py::module &m) { .value("Orthogonal", ProjectionMode::Orthogonal) .export_values(); - py::enum_(m, "DisplayMode", py::arithmetic()) + py::enum_(m, "DisplayMode") .value("Fill", taichi::lang::PolygonMode::Fill) .value("Line", taichi::lang::PolygonMode::Line) .value("Point", taichi::lang::PolygonMode::Point) From 036bfed8f6dac4c745e6c1d925ecdf7d84442dbb Mon Sep 17 00:00:00 2001 From: Mocki <34432001+Morcki@users.noreply.github.com> Date: Tue, 2 Aug 2022 09:54:33 +0800 Subject: [PATCH 14/27] Update taichi/ui/backends/vulkan/renderable.cpp Co-authored-by: Dunfan Lu --- taichi/ui/backends/vulkan/renderable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/ui/backends/vulkan/renderable.cpp b/taichi/ui/backends/vulkan/renderable.cpp index bfca1bb66770a..1a17dda310fd8 100644 --- a/taichi/ui/backends/vulkan/renderable.cpp +++ b/taichi/ui/backends/vulkan/renderable.cpp @@ -48,7 +48,7 @@ void Renderable::update_data(const RenderableInfo &info) { prog->flush(); } - bool is_pipeline_reset = false; + bool needs_pipeline_reset = false; // Check if we need to update Graphics Pipeline if (info.display_mode != config_.polygon_type) { From 0ed87b59dcf00dd39cf795c10cf2997ed6765710 Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 10:00:16 +0800 Subject: [PATCH 15/27] fix some small questions --- taichi/ui/backends/vulkan/renderer.h | 2 +- taichi/ui/common/app_config.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/taichi/ui/backends/vulkan/renderer.h b/taichi/ui/backends/vulkan/renderer.h index d8ecfa8455772..e7e0084e67346 100644 --- a/taichi/ui/backends/vulkan/renderer.h +++ b/taichi/ui/backends/vulkan/renderer.h @@ -78,7 +78,7 @@ class TI_DLL_EXPORT Renderer { taichi::lang::StreamSemaphore get_render_complete_semaphore(); private: - glm::vec3 background_color_ = glm::vec3(0.f, 0.f, 0.0f); + glm::vec3 background_color_ = glm::vec3(0.f, 0.f, 0.f); std::vector> renderables_; int next_renderable_; diff --git a/taichi/ui/common/app_config.h b/taichi/ui/common/app_config.h index 048cf1a950fd2..81a92800313c9 100644 --- a/taichi/ui/common/app_config.h +++ b/taichi/ui/common/app_config.h @@ -3,7 +3,6 @@ #include #include "taichi/ui/utils/utils.h" #include "taichi/rhi/arch.h" -#include "taichi/rhi/vulkan/vulkan_device.h" namespace taichi { namespace ui { From a14a0cd62b7a4d7d6028aa25d6c4ac57c9fb2ef3 Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 10:03:07 +0800 Subject: [PATCH 16/27] fix small questions --- taichi/ui/backends/vulkan/renderable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/ui/backends/vulkan/renderable.cpp b/taichi/ui/backends/vulkan/renderable.cpp index 1a17dda310fd8..c55f1926ee156 100644 --- a/taichi/ui/backends/vulkan/renderable.cpp +++ b/taichi/ui/backends/vulkan/renderable.cpp @@ -52,7 +52,7 @@ void Renderable::update_data(const RenderableInfo &info) { // Check if we need to update Graphics Pipeline if (info.display_mode != config_.polygon_type) { - is_pipeline_reset = true; + needs_pipeline_reset = true; config_.polygon_type = info.display_mode; pipeline_.reset(); create_graphics_pipeline(); @@ -98,7 +98,7 @@ void Renderable::update_data(const RenderableInfo &info) { config_.draw_first_index = 0; } - if (is_pipeline_reset || num_vertices > config_.max_vertices_count || + if (needs_pipeline_reset || num_vertices > config_.max_vertices_count || num_indices > config_.max_indices_count) { free_buffers(); config_.max_vertices_count = num_vertices; From ea76f878b5fadddceec775ae9999f1b5e88dff3a Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 11:53:52 +0800 Subject: [PATCH 17/27] Add control the count of instances --- python/taichi/ui/scene.py | 16 ++++++++++------ taichi/python/export_ggui.cpp | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index e144e0010b291..c5de09b1a3404 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -262,14 +262,15 @@ def mesh_instance(self, two_sided=False, transforms=None, instance_offset: int = 0, + instance_count: int = None, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None, display_mode=DisplayMode.Fill): - """Declare lots of mesh instances inside the scene. + """Declare mesh instances inside the scene. - If transforms is given, then according to the shape of transforms, we will + If transforms is given, then according to the shape of transforms, it will draw mesh instances based on the transforms, and you can indicate which instance to draw first. If you indicate the index_offset and index_count, the normals will also be sliced by the args, and the shading resultes will not be affected. @@ -296,6 +297,8 @@ def mesh_instance(self, instance_offset (int, optional): Default value is 0 which means no offset to show mesh instances. Otherwise, the mesh instances will show from the `instance_offset`. + instance_count (int, optional): + Default value is None which takes the shape value of transforms. vertex_offset (int, optional): if 'indices' is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the @@ -308,10 +311,9 @@ def mesh_instance(self, within the index buffer. index_count (int, optional): only available when `indices` is provided, which is the the number - of vertices to draw. + of indices to draw. display_mode (Enum of DisplayMode, optional): - there are 3 types of diplay mode, Fill mode(Fill colors to all triagnles) - Line mode(WareFrame), Point mode. + there are 3 types of diplay mode, Fill mode (Fill faces), Line mode (WareFrame), Point mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -327,6 +329,8 @@ def mesh_instance(self, index_count = vertex_count else: index_count = indices.shape[0] + if instance_count is None: + instance_count = transforms.shape[0] if transforms and (transforms.m != 4 or transforms.n != 4): raise Exception("Error! Transform matrix must be 4x4 shape") copy_normals_to_vbo(vbo, normals) @@ -334,7 +338,7 @@ def mesh_instance(self, indices_info = get_field_info(indices) transform_info = get_field_info(transforms) self.scene.mesh_instance(vbo_info, has_per_vertex_color, indices_info, - color, two_sided, transform_info, + color, two_sided, transform_info, instance_count, instance_offset, index_count, index_offset, vertex_count, vertex_offset, display_mode) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index a2c49922fef4a..50f327b2c5cf8 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -223,6 +223,7 @@ struct PyScene { py::tuple color, bool two_sided, FieldInfo transforms, + float draw_instance_count, float draw_first_instance, float draw_index_count, float draw_first_index, @@ -245,7 +246,7 @@ struct PyScene { info.color = tuple_to_vec3(color); info.two_sided = two_sided; if (transforms.valid) { - info.num_instances = transforms.shape[0]; + info.num_instances = draw_instance_count > transforms.shape[0] ? transforms.shape[0] : (int)draw_instance_count; info.start_instance = (int)draw_first_instance; } info.mesh_attribute_info.mesh_attribute = transforms; From 766bf356b0f5edb766fc21bcb10306f4a6ffd11f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Aug 2022 03:55:11 +0000 Subject: [PATCH 18/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/scene.py | 7 ++++--- taichi/python/export_ggui.cpp | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index c5de09b1a3404..535a3a04e7928 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -338,9 +338,10 @@ def mesh_instance(self, indices_info = get_field_info(indices) transform_info = get_field_info(transforms) self.scene.mesh_instance(vbo_info, has_per_vertex_color, indices_info, - color, two_sided, transform_info, instance_count, - instance_offset, index_count, index_offset, - vertex_count, vertex_offset, display_mode) + color, two_sided, transform_info, + instance_count, instance_offset, index_count, + index_offset, vertex_count, vertex_offset, + display_mode) def particles(self, centers, diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 50f327b2c5cf8..95f779173b6d5 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -246,7 +246,9 @@ struct PyScene { info.color = tuple_to_vec3(color); info.two_sided = two_sided; if (transforms.valid) { - info.num_instances = draw_instance_count > transforms.shape[0] ? transforms.shape[0] : (int)draw_instance_count; + info.num_instances = draw_instance_count > transforms.shape[0] + ? transforms.shape[0] + : (int)draw_instance_count; info.start_instance = (int)draw_first_instance; } info.mesh_attribute_info.mesh_attribute = transforms; From 911c9972638a51f438bef4e6704ddf9be8d413b9 Mon Sep 17 00:00:00 2001 From: Mocki <34432001+Morcki@users.noreply.github.com> Date: Tue, 2 Aug 2022 12:03:21 +0800 Subject: [PATCH 19/27] Update python/taichi/ui/scene.py Co-authored-by: YuZhang --- python/taichi/ui/scene.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index 535a3a04e7928..ec6eae4f9efb3 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -298,7 +298,7 @@ def mesh_instance(self, Default value is 0 which means no offset to show mesh instances. Otherwise, the mesh instances will show from the `instance_offset`. instance_count (int, optional): - Default value is None which takes the shape value of transforms. + The default value is None. If this parameter is not provided, instance_count = transforms.shape[0] - instance_offset. vertex_offset (int, optional): if 'indices' is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the From b5d4b3a55f3615015936d92d21ce849e122c3b55 Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 14:40:26 +0800 Subject: [PATCH 20/27] fix the implenmtation of indicating count of instances --- taichi/python/export_ggui.cpp | 2 +- taichi/ui/backends/vulkan/renderables/mesh.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 95f779173b6d5..a2eab895cbeaf 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -246,10 +246,10 @@ struct PyScene { info.color = tuple_to_vec3(color); info.two_sided = two_sided; if (transforms.valid) { + info.start_instance = (int)draw_first_instance; info.num_instances = draw_instance_count > transforms.shape[0] ? transforms.shape[0] : (int)draw_instance_count; - info.start_instance = (int)draw_first_instance; } info.mesh_attribute_info.mesh_attribute = transforms; info.mesh_attribute_info.has_attribute = transforms.valid; diff --git a/taichi/ui/backends/vulkan/renderables/mesh.cpp b/taichi/ui/backends/vulkan/renderables/mesh.cpp index d431f2d5ab660..3d20a22f0496a 100644 --- a/taichi/ui/backends/vulkan/renderables/mesh.cpp +++ b/taichi/ui/backends/vulkan/renderables/mesh.cpp @@ -50,7 +50,7 @@ void Mesh::update_data(const MeshInfo &info, const Scene &scene) { "ti.i32"); } - size_t correct_mesh_ssbo_size = num_instances_ * attr_field.matrix_rows * + size_t correct_mesh_ssbo_size = attr_field.shape[0] * attr_field.matrix_rows * attr_field.matrix_cols * data_type_size(attr_field.dtype); From 1e9d4bece194ee7b0d20390692c8bffb9333c690 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Aug 2022 06:41:49 +0000 Subject: [PATCH 21/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/ui/backends/vulkan/renderables/mesh.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taichi/ui/backends/vulkan/renderables/mesh.cpp b/taichi/ui/backends/vulkan/renderables/mesh.cpp index 3d20a22f0496a..75924046947e0 100644 --- a/taichi/ui/backends/vulkan/renderables/mesh.cpp +++ b/taichi/ui/backends/vulkan/renderables/mesh.cpp @@ -50,9 +50,9 @@ void Mesh::update_data(const MeshInfo &info, const Scene &scene) { "ti.i32"); } - size_t correct_mesh_ssbo_size = attr_field.shape[0] * attr_field.matrix_rows * - attr_field.matrix_cols * - data_type_size(attr_field.dtype); + size_t correct_mesh_ssbo_size = + attr_field.shape[0] * attr_field.matrix_rows * attr_field.matrix_cols * + data_type_size(attr_field.dtype); if (correct_mesh_ssbo_size != mesh_ssbo_size_) { resize_mesh_storage_buffers(correct_mesh_ssbo_size); From 8aac7e3e2eb541085feb86f1c3da20bca88a928b Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 14:43:50 +0800 Subject: [PATCH 22/27] fix count of instances --- taichi/python/export_ggui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index a2eab895cbeaf..8fafdda7532ed 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -247,7 +247,7 @@ struct PyScene { info.two_sided = two_sided; if (transforms.valid) { info.start_instance = (int)draw_first_instance; - info.num_instances = draw_instance_count > transforms.shape[0] + info.num_instances = (draw_instance_count + info.start_instance) > transforms.shape[0] ? transforms.shape[0] : (int)draw_instance_count; } From e30b3be6aeffe67115be889666172abb84ce2447 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Aug 2022 06:45:19 +0000 Subject: [PATCH 23/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/python/export_ggui.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 8fafdda7532ed..bef488e47833a 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -247,9 +247,10 @@ struct PyScene { info.two_sided = two_sided; if (transforms.valid) { info.start_instance = (int)draw_first_instance; - info.num_instances = (draw_instance_count + info.start_instance) > transforms.shape[0] - ? transforms.shape[0] - : (int)draw_instance_count; + info.num_instances = + (draw_instance_count + info.start_instance) > transforms.shape[0] + ? transforms.shape[0] + : (int)draw_instance_count; } info.mesh_attribute_info.mesh_attribute = transforms; info.mesh_attribute_info.has_attribute = transforms.valid; From a9d89e5b99d3f80b25de389028f46d8361a72815 Mon Sep 17 00:00:00 2001 From: Morcki Date: Tue, 2 Aug 2022 14:47:45 +0800 Subject: [PATCH 24/27] fix count of instances --- taichi/python/export_ggui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 8fafdda7532ed..65e112e211b96 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -248,7 +248,7 @@ struct PyScene { if (transforms.valid) { info.start_instance = (int)draw_first_instance; info.num_instances = (draw_instance_count + info.start_instance) > transforms.shape[0] - ? transforms.shape[0] + ? (transforms.shape[0] - info.start_instance) : (int)draw_instance_count; } info.mesh_attribute_info.mesh_attribute = transforms; From b39681cd02a23240f53969c922af19b0ae479f55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Aug 2022 06:50:21 +0000 Subject: [PATCH 25/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/python/export_ggui.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 65e112e211b96..658c6a9b69727 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -247,9 +247,10 @@ struct PyScene { info.two_sided = two_sided; if (transforms.valid) { info.start_instance = (int)draw_first_instance; - info.num_instances = (draw_instance_count + info.start_instance) > transforms.shape[0] - ? (transforms.shape[0] - info.start_instance) - : (int)draw_instance_count; + info.num_instances = + (draw_instance_count + info.start_instance) > transforms.shape[0] + ? (transforms.shape[0] - info.start_instance) + : (int)draw_instance_count; } info.mesh_attribute_info.mesh_attribute = transforms; info.mesh_attribute_info.has_attribute = transforms.valid; From ea81f8146b6a78d752895a6e86a26b15703fd99c Mon Sep 17 00:00:00 2001 From: Morcki Date: Wed, 3 Aug 2022 14:04:06 +0800 Subject: [PATCH 26/27] drop display mode, change it to show_warefram --- python/taichi/ui/scene.py | 39 +++++------------------- python/taichi/ui/ui.py | 2 +- taichi/python/export_ggui.cpp | 8 ++--- taichi/ui/backends/vulkan/renderable.cpp | 6 ++-- taichi/ui/backends/vulkan/renderable.h | 2 +- 5 files changed, 17 insertions(+), 40 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index ec6eae4f9efb3..22647ad0438f6 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -12,28 +12,6 @@ normals_field_cache = {} - -class DisplayMode_: - Fill = _ti_core.DisplayMode.Fill if _ti_core.GGUI_AVAILABLE else None - Line = _ti_core.DisplayMode.Line if _ti_core.GGUI_AVAILABLE else None - Point = _ti_core.DisplayMode.Point if _ti_core.GGUI_AVAILABLE else None - - @staticmethod - def __call__(mode: int): - if mode == 0: - return DisplayMode_.Fill - if mode == 1: - return DisplayMode_.Line - if mode == 2: - return DisplayMode_.Point - raise Exception( - "Error!Only support 3 kinds of DisplayMode(0:Fill, 1:Line, 2:Point)" - ) - - -DisplayMode = DisplayMode_() - - def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] @@ -192,7 +170,7 @@ def mesh(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode=DisplayMode.Fill): + show_wareframe: bool = False): """Declare a mesh inside the scene. if you indicate the index_offset and index_count, the normals will also @@ -227,9 +205,8 @@ def mesh(self, index_count (int, optional): only available when `indices` is provided, which is the the number of vertices to draw. - display_mode (Enum of DisplayMode, optional): - there are 3 types of diplay mode, Fill mode(Fill colors to all triagnles) - Line mode(WareFrame), Point mode. + show_wareframe (bool, optional): + turn on/off WareFrame mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -251,7 +228,7 @@ def mesh(self, self.scene.mesh(vbo_info, has_per_vertex_color, indices_info, color, two_sided, index_count, index_offset, vertex_count, - vertex_offset, display_mode) + vertex_offset, show_wareframe) def mesh_instance(self, vertices, @@ -267,7 +244,7 @@ def mesh_instance(self, vertex_count: int = None, index_offset: int = 0, index_count: int = None, - display_mode=DisplayMode.Fill): + show_wareframe: bool = False): """Declare mesh instances inside the scene. If transforms is given, then according to the shape of transforms, it will @@ -312,8 +289,8 @@ def mesh_instance(self, index_count (int, optional): only available when `indices` is provided, which is the the number of indices to draw. - display_mode (Enum of DisplayMode, optional): - there are 3 types of diplay mode, Fill mode (Fill faces), Line mode (WareFrame), Point mode. + show_wareframe (bool, optional): + turn on/off WareFrame mode. """ vbo = get_vbo_field(vertices) copy_vertices_to_vbo(vbo, vertices) @@ -341,7 +318,7 @@ def mesh_instance(self, color, two_sided, transform_info, instance_count, instance_offset, index_count, index_offset, vertex_count, vertex_offset, - display_mode) + show_wareframe) def particles(self, centers, diff --git a/python/taichi/ui/ui.py b/python/taichi/ui/ui.py index daa98bc6328cf..fea324e19070b 100644 --- a/python/taichi/ui/ui.py +++ b/python/taichi/ui/ui.py @@ -4,7 +4,7 @@ from .canvas import Canvas # pylint: disable=unused-import from .constants import * # pylint: disable=unused-import,wildcard-import from .imgui import Gui # pylint: disable=unused-import -from .scene import DisplayMode, Scene # pylint: disable=unused-import +from .scene import Scene # pylint: disable=unused-import from .utils import check_ggui_availability from .window import Window # pylint: disable=unused-import diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 65e112e211b96..9c010a9335659 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -176,7 +176,7 @@ struct PyScene { float draw_first_index, float draw_vertex_count, float draw_first_vertex, - taichi::lang::PolygonMode display_mode) { + bool show_wareframe) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -186,7 +186,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = display_mode; + renderable_info.display_mode = show_wareframe ? taichi::lang::PolygonMode::Line : taichi::lang::PolygonMode::Fill; MeshInfo info; info.renderable_info = renderable_info; @@ -229,7 +229,7 @@ struct PyScene { float draw_first_index, float draw_vertex_count, float draw_first_vertex, - taichi::lang::PolygonMode display_mode) { + bool show_wareframe) { RenderableInfo renderable_info; renderable_info.vbo = vbo; renderable_info.has_per_vertex_color = has_per_vertex_color; @@ -239,7 +239,7 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = display_mode; + renderable_info.display_mode = show_wareframe ? taichi::lang::PolygonMode::Line : taichi::lang::PolygonMode::Fill; MeshInfo info; info.renderable_info = renderable_info; diff --git a/taichi/ui/backends/vulkan/renderable.cpp b/taichi/ui/backends/vulkan/renderable.cpp index c55f1926ee156..81e92b2fc8d65 100644 --- a/taichi/ui/backends/vulkan/renderable.cpp +++ b/taichi/ui/backends/vulkan/renderable.cpp @@ -51,9 +51,9 @@ void Renderable::update_data(const RenderableInfo &info) { bool needs_pipeline_reset = false; // Check if we need to update Graphics Pipeline - if (info.display_mode != config_.polygon_type) { + if (info.display_mode != config_.polygon_mode) { needs_pipeline_reset = true; - config_.polygon_type = info.display_mode; + config_.polygon_mode = info.display_mode; pipeline_.reset(); create_graphics_pipeline(); } @@ -175,7 +175,7 @@ void Renderable::create_graphics_pipeline() { RasterParams raster_params; raster_params.prim_topology = config_.topology_type; - raster_params.polygon_mode = config_.polygon_type; + raster_params.polygon_mode = config_.polygon_mode; raster_params.depth_test = true; raster_params.depth_write = true; diff --git a/taichi/ui/backends/vulkan/renderable.h b/taichi/ui/backends/vulkan/renderable.h index 2577fa9ce62ea..6568212f75177 100644 --- a/taichi/ui/backends/vulkan/renderable.h +++ b/taichi/ui/backends/vulkan/renderable.h @@ -40,7 +40,7 @@ struct RenderableConfig { std::string fragment_shader_path; taichi::lang::TopologyType topology_type{ taichi::lang::TopologyType::Triangles}; - taichi::lang::PolygonMode polygon_type{taichi::lang::PolygonMode::Fill}; + taichi::lang::PolygonMode polygon_mode{taichi::lang::PolygonMode::Fill}; VertexAttributes vbo_attrs{VboHelpers::all()}; size_t vbo_size() const { From 266984f165595ca6864ea361ece746f63f080a74 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 06:08:14 +0000 Subject: [PATCH 27/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/ui/scene.py | 1 + taichi/python/export_ggui.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/taichi/ui/scene.py b/python/taichi/ui/scene.py index 22647ad0438f6..efb44ec5ec920 100644 --- a/python/taichi/ui/scene.py +++ b/python/taichi/ui/scene.py @@ -12,6 +12,7 @@ normals_field_cache = {} + def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] diff --git a/taichi/python/export_ggui.cpp b/taichi/python/export_ggui.cpp index 983d3bd44ddf7..7c5be1a917b24 100644 --- a/taichi/python/export_ggui.cpp +++ b/taichi/python/export_ggui.cpp @@ -186,7 +186,9 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = show_wareframe ? taichi::lang::PolygonMode::Line : taichi::lang::PolygonMode::Fill; + renderable_info.display_mode = show_wareframe + ? taichi::lang::PolygonMode::Line + : taichi::lang::PolygonMode::Fill; MeshInfo info; info.renderable_info = renderable_info; @@ -239,7 +241,9 @@ struct PyScene { renderable_info.draw_first_index = (int)draw_first_index; renderable_info.draw_vertex_count = (int)draw_vertex_count; renderable_info.draw_first_vertex = (int)draw_first_vertex; - renderable_info.display_mode = show_wareframe ? taichi::lang::PolygonMode::Line : taichi::lang::PolygonMode::Fill; + renderable_info.display_mode = show_wareframe + ? taichi::lang::PolygonMode::Line + : taichi::lang::PolygonMode::Fill; MeshInfo info; info.renderable_info = renderable_info;