From 1be827e52a936eeb6a57779603b7254eaea72ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=96=8C?= <1931127624@qq.com> Date: Thu, 27 Aug 2020 13:58:14 +0800 Subject: [PATCH] [error] [opengl] Better error message when int64 or sparse SNode not supported for OpenGL (#1783) * [error] [opengl] Better error message when int64 or sparse SNode not supported for OpenGL * fix * [skip ci] missed listman * [skip ci] enforce code format Co-authored-by: Taichi Gardener --- taichi/backends/metal/struct_metal.cpp | 7 +++++-- taichi/backends/opengl/codegen_opengl.cpp | 9 ++++++++- taichi/backends/opengl/struct_opengl.cpp | 7 +++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/taichi/backends/metal/struct_metal.cpp b/taichi/backends/metal/struct_metal.cpp index 1533e01f42e25..f1901c385e35c 100644 --- a/taichi/backends/metal/struct_metal.cpp +++ b/taichi/backends/metal/struct_metal.cpp @@ -227,8 +227,11 @@ class StructCompiler { emit(" SNodeRep_{} rep_;", snty_name); emit("}};"); } else { - TI_ERROR("SNodeType={} not supported on Metal", snode_type_name(snty)); - TI_NOT_IMPLEMENTED; + TI_ERROR( + "SNodeType={} not supported on OpenGL\n" + "Consider use ti.init(ti.cpu) or ti.init(ti.cuda) if you " + "want to use sparse data structures", + snode_type_name(snode.type)); } emit(""); } diff --git a/taichi/backends/opengl/codegen_opengl.cpp b/taichi/backends/opengl/codegen_opengl.cpp index fc1742537a64e..ad81e5ee27e2b 100644 --- a/taichi/backends/opengl/codegen_opengl.cpp +++ b/taichi/backends/opengl/codegen_opengl.cpp @@ -104,8 +104,13 @@ class KernelGen : public IRVisitor { // Note that the following two functions not only returns the corresponding // data type, but also **records** the usage of `i64` and `f64`. std::string opengl_data_type_short_name(DataType dt) { - if (dt == DataType::i64) + if (dt == DataType::i64) { + if (!TI_OPENGL_REQUIRE(used, GL_ARB_gpu_shader_int64)) { + TI_ERROR( + "Extension GL_ARB_gpu_shader_int64 not supported on your OpenGL"); + } used.int64 = true; + } if (dt == DataType::f64) used.float64 = true; return data_type_short_name(dt); @@ -811,6 +816,7 @@ class KernelGen : public IRVisitor { void generate_struct_for_kernel(OffloadedStmt *stmt) { TI_ASSERT(stmt->task_type == OffloadedStmt::TaskType::struct_for); + used.listman = true; const std::string glsl_kernel_name = make_kernel_name(); emit("void {}()", glsl_kernel_name); this->glsl_kernel_name_ = glsl_kernel_name; @@ -829,6 +835,7 @@ class KernelGen : public IRVisitor { void generate_clear_list_kernel(OffloadedStmt *stmt) { TI_ASSERT(stmt->task_type == OffloadedStmt::TaskType::clear_list); + used.listman = true; const std::string glsl_kernel_name = make_kernel_name(); emit("void {}()", glsl_kernel_name); this->glsl_kernel_name_ = glsl_kernel_name; diff --git a/taichi/backends/opengl/struct_opengl.cpp b/taichi/backends/opengl/struct_opengl.cpp index 5a2b340d17645..1470123e771ac 100644 --- a/taichi/backends/opengl/struct_opengl.cpp +++ b/taichi/backends/opengl/struct_opengl.cpp @@ -72,8 +72,11 @@ void OpenglStructCompiler::generate_types(const SNode &snode) { snode_info.stride = snode_child_info.stride * n + extension; // my stride snode_info.elem_stride = snode_child_info.stride; // my child stride } else { - TI_ERROR("SNodeType={} not supported on OpenGL", - snode_type_name(snode.type)); + TI_ERROR( + "SNodeType={} not supported on OpenGL\n" + "Consider use ti.init(ti.cpu) or ti.init(ti.cuda) if you " + "want to use sparse data structures", + snode_type_name(snode.type)); TI_NOT_IMPLEMENTED; } }