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.
This commit is contained in:
Clément Foucault
2025-05-26 11:09:33 +02:00
parent 8bba1c8056
commit eb37d19b41

View File

@@ -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.",