From 3562433ae7a9f730f631e1f22145fd300647f7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 4 Apr 2025 14:23:09 +0200 Subject: [PATCH] pyGPU: Deprecate `Shader.program` getter This is getting in the way of making the GPUShader API more threadsafe. This getter already doesn't work for vulkan and Metal, and has very limited usage. Keeping the python function to avoid errors and display a deprecation warning. Pull Request: https://projects.blender.org/blender/blender/pulls/136983 --- source/blender/gpu/GPU_shader.hh | 3 --- source/blender/gpu/intern/gpu_shader.cc | 11 ----------- source/blender/gpu/intern/gpu_shader_private.hh | 3 --- source/blender/gpu/metal/mtl_shader.hh | 6 ------ source/blender/gpu/opengl/gl_shader.cc | 12 ------------ source/blender/gpu/opengl/gl_shader.hh | 3 --- source/blender/gpu/vulkan/vk_shader.cc | 5 ----- source/blender/gpu/vulkan/vk_shader.hh | 3 --- source/blender/python/gpu/gpu_py_shader.cc | 7 +++++-- 9 files changed, 5 insertions(+), 48 deletions(-) diff --git a/source/blender/gpu/GPU_shader.hh b/source/blender/gpu/GPU_shader.hh index 81a89abbec2..6030524c7d4 100644 --- a/source/blender/gpu/GPU_shader.hh +++ b/source/blender/gpu/GPU_shader.hh @@ -335,9 +335,6 @@ void GPU_shader_warm_cache(GPUShader *shader, int limit); * called. */ void GPU_shader_set_parent(GPUShader *shader, GPUShader *parent); -/** DEPRECATED: Kept only because of BGL API. */ -int GPU_shader_get_program(GPUShader *shader); - /** * Indexed commonly used uniform name for faster lookup into the uniform cache. */ diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 077927a3b04..69482b682e7 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -662,17 +662,6 @@ bool GPU_shader_get_ssbo_input_info(const GPUShader *shader, int ssbo_location, /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Getters - * \{ */ - -int GPU_shader_get_program(GPUShader *shader) -{ - return unwrap(shader)->program_handle_get(); -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Uniforms setters * \{ */ diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh index d3d7b1efeaa..c8bac348f56 100644 --- a/source/blender/gpu/intern/gpu_shader_private.hh +++ b/source/blender/gpu/intern/gpu_shader_private.hh @@ -115,9 +115,6 @@ class Shader { virtual std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const = 0; virtual std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const = 0; - /* DEPRECATED: Kept only because of BGL API. */ - virtual int program_handle_get() const = 0; - StringRefNull name_get() const { return name; diff --git a/source/blender/gpu/metal/mtl_shader.hh b/source/blender/gpu/metal/mtl_shader.hh index a663e316507..b7010192a53 100644 --- a/source/blender/gpu/metal/mtl_shader.hh +++ b/source/blender/gpu/metal/mtl_shader.hh @@ -290,12 +290,6 @@ class MTLShader : public Shader { bool get_push_constant_is_dirty(); void push_constant_bindstate_mark_dirty(bool is_dirty); - /* DEPRECATED: Kept only because of BGL API. (Returning -1 in METAL). */ - int program_handle_get() const override - { - return -1; - } - /* Metal shader properties and source mapping. */ void set_vertex_function_name(NSString *vetex_function_name); void set_fragment_function_name(NSString *fragment_function_name); diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 63f394268c8..fd718e231e8 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -1357,18 +1357,6 @@ void GLShader::uniform_int(int location, int comp_len, int array_size, const int /** \} */ -/* -------------------------------------------------------------------- */ -/** \name GPUVertFormat from Shader - * \{ */ - -int GLShader::program_handle_get() const -{ - BLI_assert(program_active_); - return program_active_->program_id; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Sources * \{ */ diff --git a/source/blender/gpu/opengl/gl_shader.hh b/source/blender/gpu/opengl/gl_shader.hh index aa1537705c0..8b3c3bea4da 100644 --- a/source/blender/gpu/opengl/gl_shader.hh +++ b/source/blender/gpu/opengl/gl_shader.hh @@ -180,9 +180,6 @@ class GLShader : public Shader { void uniform_float(int location, int comp_len, int array_size, const float *data) override; void uniform_int(int location, int comp_len, int array_size, const int *data) override; - /** DEPRECATED: Kept only because of BGL API. */ - int program_handle_get() const override; - bool is_compute() const { if (!vertex_sources_.is_empty()) { diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc index 73b0abdfbad..791d38d0427 100644 --- a/source/blender/gpu/vulkan/vk_shader.cc +++ b/source/blender/gpu/vulkan/vk_shader.cc @@ -1355,11 +1355,6 @@ VkPipeline VKShader::ensure_and_get_graphics_pipeline(GPUPrimType primitive, return vk_pipeline; } -int VKShader::program_handle_get() const -{ - return -1; -} - const VKShaderInterface &VKShader::interface_get() const { BLI_assert_msg(interface != nullptr, diff --git a/source/blender/gpu/vulkan/vk_shader.hh b/source/blender/gpu/vulkan/vk_shader.hh index d6113e09ca6..dfe80e830a1 100644 --- a/source/blender/gpu/vulkan/vk_shader.hh +++ b/source/blender/gpu/vulkan/vk_shader.hh @@ -89,9 +89,6 @@ class VKShader : public Shader { std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override; std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override; - /* DEPRECATED: Kept only because of BGL API. */ - int program_handle_get() const override; - VkPipeline ensure_and_get_compute_pipeline(); VkPipeline ensure_and_get_graphics_pipeline(GPUPrimType primitive, VKVertexAttributeObject &vao, diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index fde31e0444f..aa740735321 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -865,11 +865,14 @@ PyDoc_STRVAR( /* Wrap. */ pygpu_shader_program_doc, "The name of the program object for use by the OpenGL API (read-only).\n" + "This is deprecated and will always return -1.\n" "\n" ":type: int"); -static PyObject *pygpu_shader_program_get(BPyGPUShader *self, void * /*closure*/) +static PyObject *pygpu_shader_program_get(BPyGPUShader * /*self*/, void * /*closure*/) { - return PyLong_FromLong(GPU_shader_get_program(self->shader)); + PyErr_WarnEx( + PyExc_DeprecationWarning, "'program' is deprecated. No valid handle will be returned.", 1); + return PyLong_FromLong(-1); } static PyGetSetDef pygpu_shader__tp_getseters[] = {