Motivation: When discussing with @Jeroen-Bakker and @aras_p about how to approach sorting when rendering Gaussian splats in Blender, we realised that compute shaders could help there (and have many other use cases), and that also due to Blender 4.0 being on OpenGL >= 4.3, we can now rely on compute shaders existing. This PR is an initial pass for that functionality. It comes with a Python example, which runs a compute shader and saves the output to a texture, which is then rendered in the viewport. There is no exposed support for storage buffers yet, but I expect I'll be able to work on them soon if this is accepted. The newly added parts are: 1. `gpu.compute.dispatch()` 2. a way set the compute source to `GPUShaderCreateInfo`: `shader_info.compute_source()` 3. a way to set the image store for `GPUShaderCreateInfo`: `shader_info.image()` 4. a way to set the `local_group_size` for `GPUShaderCreateInfo`: `shader_info.local_group_size(x,y,z)` 5. a way to get `max_work_group_size` from capabilities: `gpu.capabilities.max_work_group_size_get(index)` 6. a way to get `max_work_group_count` from capabilities: `gpu.capabilities.max_work_group_count_get(index)` Pull Request: https://projects.blender.org/blender/blender/pulls/114238
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup bpygpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef __cplusplus
|
|
# include "../generic/py_capi_utils.h"
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Make sure that there is always a reference count for PyObjects of type String as the strings are
|
|
* passed by reference in the #GPUStageInterfaceInfo and #GPUShaderCreateInfo APIs. */
|
|
#define USE_GPU_PY_REFERENCES
|
|
|
|
/* `gpu_py_shader.cc` */
|
|
|
|
extern PyTypeObject BPyGPUShader_Type;
|
|
|
|
#define BPyGPUShader_Check(v) (Py_TYPE(v) == &BPyGPUShader_Type)
|
|
|
|
typedef struct BPyGPUShader {
|
|
PyObject_VAR_HEAD
|
|
struct GPUShader *shader;
|
|
bool is_builtin;
|
|
} BPyGPUShader;
|
|
|
|
PyObject *BPyGPUShader_CreatePyObject(struct GPUShader *shader, bool is_builtin);
|
|
PyObject *bpygpu_shader_init(void);
|
|
|
|
/* gpu_py_shader_create_info.cc */
|
|
|
|
extern const struct PyC_StringEnumItems pygpu_attrtype_items[];
|
|
extern PyTypeObject BPyGPUShaderCreateInfo_Type;
|
|
extern PyTypeObject BPyGPUStageInterfaceInfo_Type;
|
|
|
|
#define BPyGPUShaderCreateInfo_Check(v) (Py_TYPE(v) == &BPyGPUShaderCreateInfo_Type)
|
|
#define BPyGPUStageInterfaceInfo_Check(v) (Py_TYPE(v) == &BPyGPUStageInterfaceInfo_Type)
|
|
|
|
typedef struct BPyGPUStageInterfaceInfo {
|
|
PyObject_VAR_HEAD
|
|
struct GPUStageInterfaceInfo *interface;
|
|
#ifdef USE_GPU_PY_REFERENCES
|
|
/* Just to keep a user to prevent freeing buf's we're using. */
|
|
PyObject *references;
|
|
#endif
|
|
} BPyGPUStageInterfaceInfo;
|
|
|
|
typedef struct BPyGPUShaderCreateInfo {
|
|
PyObject_VAR_HEAD
|
|
struct GPUShaderCreateInfo *info;
|
|
#ifdef USE_GPU_PY_REFERENCES
|
|
/* Just to keep a user to prevent freeing buf's we're using. */
|
|
PyObject *vertex_source;
|
|
PyObject *fragment_source;
|
|
PyObject *compute_source;
|
|
PyObject *typedef_source;
|
|
PyObject *references;
|
|
#endif
|
|
size_t constants_total_size;
|
|
} BPyGPUShaderCreateInfo;
|
|
|
|
PyObject *BPyGPUStageInterfaceInfo_CreatePyObject(struct GPUStageInterfaceInfo *interface);
|
|
PyObject *BPyGPUShaderCreateInfo_CreatePyObject(struct GPUShaderCreateInfo *info);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|