33 for (
const auto &def : info.
defines_) {
34 defines +=
"#define ";
70 sources.
append(
"#define GPU_SHADER\n");
73 sources.
append(
"#define GPU_ATI\n");
76 sources.
append(
"#define GPU_NVIDIA\n");
79 sources.
append(
"#define GPU_INTEL\n");
83 sources.
append(
"#define OS_WIN\n");
86 sources.
append(
"#define OS_MAC\n");
89 sources.
append(
"#define OS_UNIX\n");
95 sources.
append(
"#define GPU_OPENGL\n");
98 BLI_assert(
false &&
"Invalid GPU Backend Type");
103 sources.
append(
"#define GPU_DEPRECATED_AMD_DRIVER\n");
108 const char *fragcode,
109 const char *geomcode,
110 const char *computecode,
114 const char **tf_names,
119 BLI_assert(((fragcode !=
nullptr) && (vertcode !=
nullptr) && (computecode ==
nullptr)) ||
120 ((fragcode ==
nullptr) && (vertcode ==
nullptr) && (geomcode ==
nullptr) &&
121 (computecode !=
nullptr)));
128 sources.
append(
"#define GPU_VERTEX_SHADER\n");
129 sources.
append(
"#define IN_OUT out\n");
131 sources.
append(
"#define USE_GEOMETRY_SHADER\n");
144 sources.
append(
"#define GPU_FRAGMENT_SHADER\n");
145 sources.
append(
"#define IN_OUT in\n");
147 sources.
append(
"#define USE_GEOMETRY_SHADER\n");
163 sources.
append(
"#define GPU_GEOMETRY_SHADER\n");
175 sources.
append(
"#define GPU_COMPUTE_SHADER\n");
182 sources.
append(computecode);
187 if (tf_names !=
nullptr && tf_count > 0) {
212 const char *fragcode,
213 const char *geomcode,
257 if (
error.length() == 0) {
271 printf(
"Warning: Trying to compile \"%s\" which was not marked for static compilation.\n",
287 if (!
error.empty()) {
288 printf(
"%s\n",
error.c_str());
298 defines +=
"#define USE_GPU_SHADER_CREATE_INFO\n";
314 std::string
interface = shader->vertex_interface_declare(info);
318 sources.append(
"#define GPU_VERTEX_SHADER\n");
319 if (!info.geometry_source_.is_empty()) {
320 sources.append(
"#define USE_GEOMETRY_SHADER\n");
322 sources.append(defines.c_str());
323 sources.extend(typedefs);
324 sources.append(resources.c_str());
325 sources.append(interface.c_str());
326 sources.extend(code);
327 sources.extend(info.dependencies_generated);
328 sources.append(info.vertex_source_generated.c_str());
335 std::string
interface = shader->fragment_interface_declare(info);
339 sources.append(
"#define GPU_FRAGMENT_SHADER\n");
340 if (!info.geometry_source_.is_empty()) {
341 sources.append(
"#define USE_GEOMETRY_SHADER\n");
343 sources.append(defines.c_str());
344 sources.extend(typedefs);
345 sources.append(resources.c_str());
346 sources.append(interface.c_str());
347 sources.extend(code);
348 sources.extend(info.dependencies_generated);
349 sources.append(info.fragment_source_generated.c_str());
357 std::string
interface = shader->geometry_interface_declare(info);
361 sources.append(
"#define GPU_GEOMETRY_SHADER\n");
362 sources.append(defines.c_str());
363 sources.extend(typedefs);
364 sources.append(resources.c_str());
365 sources.append(layout.c_str());
366 sources.append(interface.c_str());
367 sources.append(info.geometry_source_generated.c_str());
368 sources.extend(code);
379 sources.
append(
"#define GPU_COMPUTE_SHADER\n");
380 sources.
append(defines.c_str());
382 sources.
append(resources.c_str());
383 sources.
append(layout.c_str());
400 const char *fragcode,
401 const char *geomcode,
406 char *libcodecat =
nullptr;
408 if (libcode ==
nullptr) {
416 const char *shname = name !=
nullptr ? name :
"pyGPUShader";
435 bool is_alloc =
false;
436 if (str_arr ==
nullptr) {
441 while (str_arr[0] && str_arr[0][0] ==
'\0') {
445 for (i = 0; str_arr[i]; i++) {
446 if (i != 0 && str_arr[i][0] !=
'\0') {
450 *r_is_alloc = is_alloc;
464 } str_dst[4] = {{
nullptr}};
467 for (
int i = 0; i <
ARRAY_SIZE(str_src); i++) {
475 str_dst[0].
str, str_dst[1].
str, str_dst[2].
str,
nullptr, str_dst[3].
str, name);
477 for (
auto &i : str_dst) {
497 if (ctx->
shader != shader) {
532 return unwrap(shader)->name_get();
545 return unwrap(shader)->transform_feedback_enable(vertbuf);
550 unwrap(shader)->transform_feedback_disable();
562 const ShaderInput *uniform = interface->uniform_get(name);
563 return uniform ? uniform->
location : -1;
581 const ShaderInput *ssbo = interface->ssbo_get(name);
596 return ubo ? ubo->
binding : -1;
603 return tex ?
tex->binding : -1;
609 const ShaderInput *attr = interface->attr_get(name);
621 return unwrap(shader)->program_handle_get();
631 GPUShader *shader,
int loc,
int len,
int arraysize,
const float *value)
633 unwrap(shader)->uniform_float(loc,
len, arraysize, value);
637 GPUShader *shader,
int loc,
int len,
int arraysize,
const int *value)
639 unwrap(shader)->uniform_int(loc,
len, arraysize, value);
665 const float data[2] = {
x,
y};
671 const float data[3] = {
x,
y,
z};
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_string_join_arrayN(const char *strings[], uint strings_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool GPU_crappy_amd_driver(void)
eGPUBackendType GPU_backend_get_type(void)
void GPU_debug_group_end(void)
void GPU_debug_group_begin(const char *name)
#define GPU_DEBUG_SHADER_COMPILATION_GROUP
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
bool GPU_matrix_dirty_get(void)
void GPU_matrix_bind(struct GPUShader *shader)
struct GPUShader GPUShader
@ GPU_UNIFORM_SRGB_TRANSFORM
struct GPUShaderCreateInfo GPUShaderCreateInfo
struct GPUVertBuf GPUVertBuf
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr bool is_empty() const
constexpr const char * c_str() const
void append(const T &value)
void extend(Span< T > array)
static GPUBackend * get()
virtual Shader * shader_alloc(const char *name)=0
int32_t uniform_builtin(const GPUUniformBuiltin builtin) const
int32_t ubo_builtin(const GPUUniformBlockBuiltin builtin) const
virtual void transform_feedback_names_set(Span< const char * > name_list, eGPUShaderTFBType geom_type)=0
std::string defines_declare(const shader::ShaderCreateInfo &info) const
virtual void fragment_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const =0
ShaderInterface * interface
virtual bool finalize(const shader::ShaderCreateInfo *info=nullptr)=0
virtual std::string resources_declare(const shader::ShaderCreateInfo &info) const =0
virtual void vertex_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual void compute_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual void geometry_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const =0
GPUShader * GPU_shader_create(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
void GPU_shader_uniform_vector_int(GPUShader *shader, int loc, int len, int arraysize, const int *value)
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
void GPU_shader_set_srgb_uniform(GPUShader *shader)
GPUShader * GPU_shader_create_from_python(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *name)
static bool gpu_shader_srgb_uniform_dirty_get()
static const char * string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
static int g_shader_builtin_srgb_transform
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float(*val)[2])
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_bind(GPUShader *gpu_shader)
static void standard_defines(Vector< const char * > &sources)
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
GPUShader * GPU_shader_create_from_info_name(const char *info_name)
void GPU_shader_uniform_vector(GPUShader *shader, int loc, int len, int arraysize, const float *value)
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
GPUShader * GPU_shader_create_ex(const char *vertcode, const char *fragcode, const char *geomcode, const char *computecode, const char *libcode, const char *defines, const eGPUShaderTFBType tf_type, const char **tf_names, const int tf_count, const char *shname)
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float(*val)[4])
char datatoc_gpu_shader_colorspace_lib_glsl[]
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
void GPU_shader_transform_feedback_disable(GPUShader *shader)
int GPU_shader_get_program(GPUShader *shader)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
const char * GPU_shader_get_name(GPUShader *shader)
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
GPUShader * GPU_shader_create_compute(const char *computecode, const char *libcode, const char *defines, const char *shname)
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
void GPU_shader_free(GPUShader *shader)
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
static bool g_shader_builtin_srgb_is_dirty
bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf)
int GPU_shader_get_ssbo(GPUShader *shader, const char *name)
const GPUShaderCreateInfo * GPU_shader_create_info_get(const char *info_name)
struct GPUShader * GPU_shader_create_from_arrays_impl(const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
const GPUShaderCreateInfo * gpu_shader_create_info_get(const char *info_name)
ccl_gpu_kernel_postfix ccl_global float int int int int sh
void(* MEM_freeN)(void *vmemh)
static void error(const char *str)
StringRefNull gpu_shader_dependency_get_source(const StringRefNull shader_source_name)
Vector< const char * > gpu_shader_dependency_get_resolved_source(const StringRefNull shader_source_name)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
StringRefNull vertex_source_
StringRefNull compute_source_
Vector< std::array< StringRefNull, 2 > > defines_
std::string check_error() const
StringRefNull geometry_source_
std::string typedef_source_generated
bool legacy_resource_location_
StringRefNull fragment_source_
bool do_static_compilation_
Vector< StringRefNull > typedef_sources_