From eb37d19b41103629970d1dfaeea199d6119ecc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 26 May 2025 11:09:33 +0200 Subject: [PATCH] GPU: Python: Raise error when creating shaders without create info This is adding a hard error for backends do that do not supports it. Even without this, the backend would return a nullptr. But the error message in this case was just "see console for more details" without any additional detail. Which was confusing. --- source/blender/python/gpu/gpu_py_shader.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index dbdbb5bb0d3..28a1278f00d 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -13,6 +13,7 @@ #include "BLI_utildefines.h" +#include "GPU_context.hh" #include "GPU_shader.hh" #include "GPU_texture.hh" #include "GPU_uniform_buffer.hh" @@ -109,6 +110,20 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject * /*type*/, PyObject *args, P { BPYGPU_IS_INIT_OR_ERROR_OBJ; + if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) { + PyErr_SetString(PyExc_Exception, + "Direct shader creation is not supported on Vulkan. " + "Use gpu.shader.create_from_info(shader_info) instead."); + return nullptr; + } + + if (GPU_backend_get_type() == GPU_BACKEND_METAL) { + PyErr_SetString(PyExc_Exception, + "Direct shader creation is not supported on Metal. " + "Use gpu.shader.create_from_info(shader_info) instead."); + return nullptr; + } + PyErr_WarnEx(PyExc_DeprecationWarning, "Direct shader creation is deprecated. " "Use gpu.shader.create_from_info(shader_info) instead.",