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] Allowing recreating GGUI windows after ti.reset(). #3389

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion taichi/backends/interop/vulkan_cuda_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ void memcpy_cuda_to_vulkan(DevicePtr dst, DevicePtr src, uint64_t size) {
DeviceAllocation dst_alloc(dst);
DeviceAllocation src_alloc(src);

static std::unordered_map<int, unsigned char *> alloc_base_ptrs;
static std::unordered_map<
VulkanDevice *,
std::unordered_map<CudaDevice *,
std::unordered_map<int, unsigned char *>>>
alloc_base_ptrs_all;
std::unordered_map<int, unsigned char *> &alloc_base_ptrs =
alloc_base_ptrs_all[vk_dev][cuda_dev];

if (alloc_base_ptrs.find(dst_alloc.alloc_id) == alloc_base_ptrs.end()) {
auto [base_mem, alloc_offset, alloc_size] =
Expand Down
12 changes: 8 additions & 4 deletions taichi/python/export_ggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace py = pybind11;
#include "taichi/ui/backends/vulkan/scene.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/ui/common/gui_base.h"
#include <memory>

TI_UI_NAMESPACE_BEGIN

Expand Down Expand Up @@ -229,7 +230,7 @@ struct PyCanvas {
};

struct PyWindow {
WindowBase *window;
std::unique_ptr<WindowBase> window{nullptr};

PyWindow(std::string name,
py::tuple res,
Expand All @@ -242,7 +243,7 @@ struct PyWindow {
vsync, show_window, package_path,
ti_arch, is_packed_mode};
// todo: support other ggui backends
window = new vulkan::Window(config);
window = std::make_unique<vulkan::Window>(config);
}

void write_image(const std::string &filename) {
Expand Down Expand Up @@ -298,8 +299,10 @@ struct PyWindow {
return py::make_tuple(x, y);
}

~PyWindow() {
delete window;
void destroy() {
if (window) {
window.reset();
}
}
};

Expand All @@ -320,6 +323,7 @@ void export_ggui(py::module &m) {
.def("get_events", &PyWindow::get_events)
.def_property("event", &PyWindow::get_current_event,
&PyWindow::set_current_event)
.def("destroy", &PyWindow::destroy)
.def("GUI", &PyWindow::GUI);

py::class_<PyCanvas>(m, "PyCanvas")
Expand Down